0%

Moya-HandyJSON

水一篇,好像以前不水一样...

Response+HandyJSON.swift

1
2
3
4
5
6
7
8
9
10
11
12
13
import Foundation
import Moya
import HandyJSON

public extension Response {
func mapObject<T: HandyJSON>(_ type: T.Type) throws -> T {
//判断code
guard let json = try mapJSON() as? [String: Any], let object = T.deserialize(from: json) else {
throw MoyaError.jsonMapping(self)
}
return object
}
}

Single+HandyJSON.swift

1
2
3
4
5
6
7
8
9
10
11
12
13
import Foundation
import RxSwift
import Moya
import HandyJSON

public extension PrimitiveSequence where TraitType == SingleTrait, ElementType == Response {

func mapObject<T: HandyJSON>(_ type: T.Type) -> Single<T> {
return flatMap {
.just(try $0.mapObject(type))
}
}
}

Moya-HandyJSON

–EOF–