一个简单的 Swift API 封装器,用于 NextBus 公共交通信息。
初始化一个交通Agency
let agency = Agency(tag: "sf-muni", title: "San Francisco Municipal Railway", regionTitle: "California-Northern")
获取 Agency
的线路
do {
let nJudah = try agency.routes().filter({ $0.tag == "N" })
} catch {
fatalError()
}
获取 Stop
的 Prediction
do {
let powellOutbound = Stop(agency: agency, stopTag: "6995", title: "Powell Station Outbound", location: (37.7843, -122.4078199), stopId: "16995")
let (predictions, _) = try powellOutbound.predictions()
} catch {
fatalError()
}
除非另有说明,否则应假定调用是同步的。 最好将调用分派到后台队列,查询线路/站点,然后在准备好更新 UI 时分派回主线程。