ObjectMapper
ObjectMapper copied to clipboard
Mapping Generics and primitive data types
Hi,
Can we use primitive data types as Generics?
Here's my JSON:
{
"result": 33
}
Here's my Model:
class Result<T: Mappable>: Mappable {
var result: T?
required init?(map: Map){
}
func mapping(map: Map) {
result <- map["result"]
}
}
What I did:
let result = Mapper<Result<Int>>().map(JSON)
I've got a compiler error:
Type 'Int' does not conform to protocol 'Mappable'
Is there any workaround?
Instead of this:
class Result<T: Mappable>
do this:
class Result<T>
Because Int
does not implement Mappable
protocol.