I want to write the follow code, the T is Array<User>
, and User is a Mappable class. but the objectMapper can not do this for me. please give me a favor
responseModel = Mapper<ResponseModel<T>>().map(JSON: value as! [String: Any])
Yeah, I know it is totally inconvenient, because if you want ot map directly an array of mappable object - you have to use explicitly a different function.
This is because Array of Mappable is not Mappable by itself. I believe this inconvenience will be fixed in swift 4.
If u understand you correctly - you want to have a wrapper object for all of your responses. Where T is its generic value. If that is the case, you can do the following:
As you are having ResponseModel<T>
, you can define ResponseArray<T>
that will define its result to be [T].
This way - you will only have to explicitly use either ResponseModel or ResponseArray, depending on your result.
Thanks @KoCMoHaBTa, that's correct.
Hi I'm having the same problem now and the language I use is Swift 4
Is there a shorter way to do this without creating more boilerplate?
I have same problem too.
Most helpful comment
Hi I'm having the same problem now and the language I use is Swift 4
Is there a shorter way to do this without creating more boilerplate?