测试测试过 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布上次发布 | 2017 年 3 月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Henrik Panhans 维护。
依赖关系 | |
Alamofire | >= 0 |
SwiftyJSON | >= 0 |
这是一个简单的 API,用 Swift 3 编写,基于 OpenWeatherMap.org 的 API
要安装,只需将 pod 'OpenWeatherSwift'
添加到您的 Podfile
使用方法
import OpenWeatherSwift
var newApi = OpenWeatherSwift(apiKey: "_your_api_key_goes_here", temperatureFormat: .Celsius)
以下参数是可用的
语言
温度格式
以下函数可用: 结果将始终是一个 JSON 对象,可以访问其中值。此外,您还可以创建一个 Weather() 对象,以方便访问 JSON 数据。
newApi.currentWeatherByCoordinates(coords: CLLocationCoordinate2D) { (results) in
let weather = Weather(data: results)
}
newApi.currentWeatherByCity(name: String) { (result) in
let weather = Weather(data: results)
}
newApi.currentWeatherByID(id: String) { (result) in
let weather = Weather(data: results)
}
newApi.currentWeatherByZIP(code: String, countryCode: String) { (result) in
let weather = Weather(data: results)
}
newApi.forecastWeatherByCoordinates(coords: CLLocationCoordinate2D, type: ForecastType) { (results) in
let forecast = Forecast(data: results, type: ForecastType)
}
newApi.forecastWeatherByID(id: String, type: ForecastType) { (results) in
let forecast = Forecast(data: results, type: ForecastType)
}
newApi.forecastWeatherByCity(name: String, type: ForecastType) { (results) in
let forecast = Forecast(data: results, type: ForecastType)
}
玩得开心,并对使用表示感谢 :)