ObjectMapper
ObjectMapper copied to clipboard
How to use Generic,like HandyJSON?
struct DSBaseResponse<T>: Mappable { init?(map: Map) { }
var code = 0
private var msg: String?
var data: T?
/// 适配没有套到data层中
var total = 0
var rows: T?
mutating func mapping(map: Map) {
msg <- map["message"]
total <- map["total"]
code <- map["code"]
rows <- map["rows"]
data <- map["data"]
}
}
T maybe is Any,[T], [String, Any],Int ... I cannot let T must confirm protocol Mappable, such as :
struct DSBaseResponse<T: Mappable>: Mappable { }
how can I design this struct? like HandyJSON, HandyJSON can use like this.
// test let res = .... network response string let result = DSBaseResponse<T>(JSONString: res.string)