class HttpResponse<T : Mappable> : Mappable {
var code: Int = 0
var msg: String?
var result: T?
required init?(map: Map) {
}
func mapping(map: Map) {
code <- map["code"]
msg <- map["msg"]
result <- map["result"]
}
}
class User: Mappable {
var username: String?
var age: Int?
var weight: Double!
var array: [Any]?
var dictionary: [String : Any] = [:]
var bestFriend: User? // Nested User object
var friends: [User]? // Array of Users
var birthday: Date?
required init?(map: Map) {
}
// Mappable
func mapping(map: Map) {
username <- map["username"]
age <- map["age"]
weight <- map["weight"]
array <- map["arr"]
dictionary <- map["dict"]
bestFriend <- map["best_friend"]
friends <- map["friends"]
birthday <- (map["birthday"], DateTransform())
}
}
But the value of result is generic, the value type has String, or the entity object like User, when I pass in the String error, the prompt 'String' does not conform to expected type 'Mappable'
I did:
let result1 = Mapper<HttpResponse<User>>().map(JSON)
let result2 = Mapper<HttpResponse<String>>().map(JSON)
result2 tost the prompt 'String' does not conform to expected type 'Mappable'
I exepected something like:
let result2 = Mapper<HttpResponse<String>>().map(JSON)
let's say I have a json object that might look like this:
My model:
But the value of result is generic, the value type has String, or the entity object like User, when I pass in the String error, the prompt 'String' does not conform to expected type 'Mappable'
I did:
result2 tost the prompt 'String' does not conform to expected type 'Mappable'
I exepected something like: