Open CoderDoraemon opened 5 years ago
删了APP设置下缓存策略
OnCache+Demo.swift requestObject 方法指定了 CleanJSONDecoder 缓存正常
import RxSwift
import RxNetwork
import CleanJSON
extension OnCache {
public func requestObject() -> Single<C> {
return target.request()
.storeCachedResponse(for: target)
.map(Network.Response<C>.self, using: CleanJSONDecoder())
.map {
if $0.success {
return $0.data
}
throw Network.Error.status(code: $0.code, message: $0.message)
}
}
}
onCache获取缓存需指定解析对应路径
/*
{
"code": 2000,
"message": "Ok",
"result": []
}
*/
BannerAPI.test(count: 10)
.onCache([BannerModel].self, atKeyPath: "result", using: CleanJSONDecoder(), { (models) in
debugPrint("onCache:", models.first?.name ?? "")
})
.requestObject()
.subscribe(onSuccess: { (models) in
debugPrint("onSuccess:", models.first?.name ?? "")
}, onError: { (error) in
debugPrint("error:", error)
})
.disposed(by: disposeBag)
这个是正常的,JSON 解析失败导致的,Demo 里面我没有处理这个,多谢反馈。
Demo中下面此示例方法在解析过程中报错
报错如下