Latest 2.2.2
License MIT
Platforms ios 8.0, osx 10.9, tvos 9.0, watchos 2.0
Dependencies SwiftyJSON

WMATAFetcher language Version License Platform


A cross-platform CocoaPod that fetches information from WMATA’s API and stores it in Train objects, which are modeled after the API’s AIMPredictionTrainInfo object.


  • iOS 8.0+
  • macOS 10.9+
  • tvOS 9.0+
  • watchOS 2.0+


WMATAFetcher is available via CocoaPods. To install it, add the following to your Podfile:

target 'TargetName' do
    pod 'WMATAFetcher'

Next, run the following in a Terminal:

$ pod install



First, create a new WMATAFetcher object, passing it your WMATA API key:

var wmataFetcher = WMATAFetcher(WMATA_API_KEY: "[YOUR_WMATA_KEY]")

Spaces between groups

The isSpaceInTrainArray BOOL determines if a Station.Space object will separate each group in the Train array (default: true).

You may initialize this value when instantiating a new WMATAFetcher object:

var wmataFetcher = WMATAFetcher(WMATA_API_KEY: "[YOUR_WMATA_KEY]", isSpaceInTrainArray: false)

You may also change the value of isSpaceInTrainArray directly:

wmataFetcher.isSpaceInTrainArray = false


Pass wmataFetcher.getStationPredictions a station code to get predictions. Implement onCompleted to handle the TrainResponse returned.

If trainResponse.errorCode is nil, we can safely force upwrap trainResponse.trains?.

let wmataFetcher = WMATAFetcher(WMATA_API_KEY: "[API KEY HERE]")

let metroCenterStationCode = Station(description: "Metro Center")!.rawValue

wmataFetcher.getStationPredictions(stationCode: metroCenterStationCode, onCompleted: {
    trainResponse in
    if trainResponse.errorCode == nil {
        for train in trainResponse.trains! {
    } else {
        switch trainResponse.errorCode! {
        case -1009:
            print("Internet connection is offline")
            print("Prediction fetch failed (Code: (trainResponse.errorCode!))")

Error Handling

TrainResponse.errorCode is an Int? representing the HTTP status code returned by WMATA’s API. If it is nil, the fetch was successful. The most common error codes are:

  1. -1009
    • The internet connection is offline
  2. 401
    • Unauthorized. This is likely a bad WMATA key.


Notable Projects

  • DC Metro Widget
    • Today extension for macOS’ Notification Center
    • Inspiration for this Pod

Available on the Mac App Store


WMATAFetcher is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "WMATAFetcher",
    "version": "2.2.2",
    "summary": "Wrapper Pod for the WMATA API",
    "description": "WMATAFetcher contains helper methods to fetch predictions from the WMATA API.nIt uses [SwiftyJSON]( to populate an array of [Train]( objects, which contain the number of cars, destination, group, line, location, and minutes until train arrival.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Christopher Rung": "[email protected]"
    "source": {
        "git": "",
        "tag": "2.2.2"
    "social_media_url": "",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "tvos": "9.0",
        "watchos": "2.0"
    "source_files": "WMATAFetcher/**/*.swift",
    "dependencies": {
        "SwiftyJSON": [
            "~> 3.0"
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This