跳转至

Core-mapResult

/// - Parameters:
///   - type: 模型类型
///   - modelKey: 模型数据路径
func mapObject<T: Modelable>(_ type: T.Type, modelKey: String? = nil) ->  Observable<T>

func mapObject<T: Modelable>(_ type: T.Type, modelKey: String? = nil) ->  Single<T>

详细说明请参考 Core 目录下的 mapResult ,这里就不再赘述


Example

let rxRequest: Single<Response>

success-obj

重新定义一个 ModelableParameterType

// MARK:- 自定义网络结果参数
struct CustomNetParameter: ModelableParameterType {
    var successValue = "000"
    var statusCodeKey = "retStatus"
    var tipStrKey = "retMsg"
}

调用 mapResult 并在闭包中返回 ModelableParameterType 实例

rxRequest.mapResult { CustomNetParameter() }
    .subscribe(onSuccess: { (isSuccess, tipStr) in
        print("isSuccess -- \(isSuccess)")
        print("tipStr -- \(tipStr)")
    }).disposed(by: disposeBag)

打印结果

isSuccess -- true
tipStr -- 获取数据成功