Core-mapResult¶
typealias MoyaMapperResult = (Bool, String)
typealias ModelableParamsBlock = ()->(ModelableParameterType)
/// Response -> MoyaMapperResult
///
/// - Parameter params: 自定义解析的设置回调
/// - Returns: MoyaMapperResult
func mapResult(params: ModelableParamsBlock? = nil) -> MoyaMapperResult
Response转换为元祖MoyaMapperResult
param1:Bool服务器返回的请求状态码是否与预先设置的成功状态码一致
param2:String服务器返回的提示语
params 用于指定特殊取值路径,在这里主要指定 successValue statusCodeKey tipStrKey
如果为 nil ,则取当前 Response 的 ModelableParameterType 为取值依据
ps: 当前Response 的 ModelableParameterType 可以通过 MoyaMapperPlugin 进行统一设置
Example¶

重新定义一个 ModelableParameterType
// MARK:- 自定义网络结果参数
struct CustomNetParameter: ModelableParameterType {
var successValue = "000"
var statusCodeKey = "retStatus"
var tipStrKey = "retMsg"
}
调用 mapResult 并在闭包中返回 ModelableParameterType 实例
let (isSuccess, tipStr) = response.mapResult { CustomNetParameter() }
print("isSuccess -- \(isSuccess)")
print("tipStr -- \(tipStr)")
打印结果
isSuccess -- true
tipStr -- 获取数据成功