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
[String: [DecodableObject]] #334
Comments
Ugh, yes. This is an issue that should disappear with Swift 3.0. The basic issue here is that contextual types like
This would help us immensely, and would mean being able to greatly simplify our API. If we could say that arrays of I think what you've come up with is a reasonable solution to this unfortunate limitation, and I don't have any immediate suggestions of how else to solve it. |
Sounds like Swift 3.0 can clean this up and would probably remove some further minor "issues". Mainly that we are using a fair amount of optionals, as well as NSDate, NSURL. I've gotten it all to work, but any time I can make something simpler I'm happy. I'd be happy to have the ticket closed, I'm happy with the answer. Thanks for writing and open sourcing Argo, it's been quite useful. |
fwiw, one of the points of Argo is that you shouldn't have to rely on optionals where they don't make sense. What issues have you run into around those (and |
Closing this but I'd still love to hear about my questions above if you have time, @ligerjohn. |
@ligerjohn Is there any update on handling the similar tasks? Thanks. |
I am trying to decode an object with arrays (JSON) into Swift, making it a Dictionary with String keys and Array values. I was able to solve it in the end, but found the solution quite inelegant compared to "normal" use of Argo. I'm hoping to get some examples of doing this more elegantly or if there aren't I'm hoping Argo could be extended to make it elegant.
The JSON structure would be something along the lines of this. All fake names to protect the innocent:
So this was my first, naïve try. It would be nice if this syntax worked. i.e. if Dictionary were treated as a Decodable the same way Array etc are.
Searching through the issues and documentation I proceeded to make this change. It worked if the dictionary did not have an Array as value, but again fails to compile if there's an array as value.
This is the final version I ended up with.
decodeVariable(j: JSON)
does work (unless I made some typos here) but it's quite inelegant and messy compared to the common case.I wanted to bring it up as even though I did solve the issue others might have similar issues and I couldn't find any info on it.
The text was updated successfully, but these errors were encountered: