当我试图编译下面的代码时,我会得到一个错误:
对成员‘json’的模糊引用(:参数:编码:headers:)
代码是从RxAlamofire Github存储库页面复制和粘贴的。
import RxSwift
import RxAlamofire
class CurrencyRest {
static func getJson() {
let stringURL = "https://api.fixer.io/latest"
// MARK: NSURLSession simple and fast
let session = URLSession.init()
_ = session.rx.json(.get, stringURL)
.observeOn(MainScheduler.instance)
.subscribe { print($0) }
}
}发布于 2017-10-01 00:46:18
要修复错误,session.rx.json(url:)是要走的路,它来自RxCocoa,尽管对于RxAlamofire,您不必使用URLSession rx扩展,而是使用json(::parameters:encoding:headers:),例如,json(.get, stringURL),它返回一个可以作为JSON使用的Observable<Any>。
https://stackoverflow.com/questions/45551049
复制相似问题