Rx-mapObjResult¶
/// - Parameters:
/// - type: 模型类型
/// - params: 自定义解析的设置回调
func mapObjResult<T: Modelable>(_ type: T.Type, params: ModelableParamsBlock? = nil) -> Observable<(MoyaMapperResult,T)>
func mapObjResult<T: Modelable>(_ type: T.Type, params: ModelableParamsBlock? = nil) -> Single<(MoyaMapperResult,T)>
详细说明请参考 Core
目录下的 mapObjResult ,这里就不再赘述
Example¶
let rxRequest: Single<Response>
struct MMModel: Modelable {
var name : String
var organization : String
var logoUrl : String
var github : String
var avatar : String
var author : String
var age : Int
init(_ json: JSON) {
name = json["name"].stringValue
organization = json["organization"].stringValue
logoUrl = json["logoUrl"].stringValue
github = json["github"].stringValue
avatar = json["avatar"].stringValue
author = json["author"].stringValue
age = json["age"].intValue
}
}
// MARK:- 自定义网络结果参数
struct CustomNetParameter: ModelableParameterType {
var successValue = "000"
var statusCodeKey = "retStatus"
var tipStrKey = "retMsg"
var modelKey = "retBody"
}
转模型
rxRequest.mapObjResult(MMModel.self) { CustomNetParameter() }
.subscribe(onSuccess: { (result, model) in
print("result -- \(result)")
print("name -- \(model.name)")
}).disposed(by: disposeBag)
打印结果
result -- (true, "获取数据成功")
name -- MoyaMapper