RxOpenWeather
使用RxSwift和Swift 5.3处理基本Open Weather Map API响应数据的响应式可解码对象
安装
简单地将RxOpenWeather添加到您的Podfile
pod 'RxOpenWeather'
使用方法
使用您的api密钥,特定的温度单位(.celsius、.fahrenheit、.kelvin)和可选的特定语言代码声明一个OpenWeatherClient。然后向客户端发送信息以请求API调用。当前OpenWeatherClient支持两个API调用 - 一个获取天气数据,直接geocoding以获取位置信息。每个API调用都返回RxSwift.Observable,您可以订阅它。
import RxSwift
import RxCocoa
import RxOpenWeather
let disposeBag = DisposeBag()
let weather = PublishSubject<OneCallResponse>()
do {
try OpenWeatherClient(apiKey: "PUT_YOUR_API_KEY_HERE",
temperatureUnit: .celsius,
language: Locale.current.languageCode)
.oneCall(latitude: 25.234, longitude: -123.432)
.bind(to: weather)
.disposed(by: disposeBag)
} catch {
print(error.localizedDescription)
}