跳转至

Rx-mapArrayResult

/// - Parameters:
///   - type: 模型类型
///   - params: 自定义解析的设置回调
func mapArrayResult<T: Modelable>(_ type: T.Type, params: ModelableParamsBlock? = nil) -> Observable<(MoyaMapperResult,[T])>

func mapArrayResult<T: Modelable>(_ type: T.Type, params: ModelableParamsBlock? = nil) -> Single<(MoyaMapperResult,[T])>

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


Example

let rxRequest: Single<Response>

success-array

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"
}

MoyaMapperResult + 模型数组

rxRequest.mapArrayResult(MMModel.self) { CustomNetParameter() }
    .subscribe(onSuccess: { (result, models) in
        let name = models[0].name
        print("result -- \(result)")
        print("count -- \(models.count)")
        print("name -- \(name)")
    }).disposed(by: disposeBag)

打印结果

result -- (true, "获取数据成功")
count -- 4
name -- MoyaMapper