Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generic array type #719

Closed
nearspears opened this issue Jan 5, 2017 · 4 comments
Closed

generic array type #719

nearspears opened this issue Jan 5, 2017 · 4 comments

Comments

@nearspears
Copy link

nearspears commented Jan 5, 2017

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])

@KoCMoHaBTa
Copy link
Contributor

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.

@tristanhimmelman
Copy link
Owner

Thanks @KoCMoHaBTa, that's correct.

@kuyazee
Copy link

kuyazee commented May 31, 2018

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?

@nasserkhosravi
Copy link

I have same problem too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants