-
Notifications
You must be signed in to change notification settings - Fork 49
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
SwiftyJSON Array extension #17
Comments
Yep. We simply cannot get it to work reliably. What we want to do, is to create an extension like extension Array : JSONDecodable where Element: JSONDecodable However it's impossible in Swift 2 and Swift3. We can cast like this of course: Element.self as? JSONDecodable.Type However, it's an internal check, that produces unexpected results. It makes every array conform to JSONDecodable, whether you like it or not. We thought that for now we might comment this extension out, because we really want to get it to work properly, not hacky. But it seems before Swift 4 it's impossible, so at least we wanted to give our users a knowledge that this hack exists, and you can manually copy and paste it into your project if needed. If you have any ideas how to make this extension work, i would be really happy to hear them, i've been struggling with this extension basically since the beginning of TRON development. |
It makes sense. Thanks for the clarification and I understand your struggle. Meanwhile, could be great to leave a note on the README because I guess some people can be confused or won't understand why they can use all other types except Array. |
Added information about this to readme, i'll leave this issue open for anybody interested(and hopefully find a way to close it with Swift 4) |
Seems like we'll be revisiting this for Swift 3.1 🚀 |
@DenHeadless Any news that this will be fixed with 3.1? |
I will look into it once final Xcode 8.3 lands, but from initial testing it seems that this issue will not be fixed. Swift 3.1 allows concrete constrained extensions, for example: extension Array where Element == String However what we need is something a little different, we need both protocol conformance and element protocol conformance: extension Array : JSONDecodable where Element: JSONDecodable |
@DenHeadless Ok I will try to find an other way |
This is now documented in Response Serializers. |
Seems like this will be possible with Swift 4.1 protocol conditional conformances. https://github.com/apple/swift/pulls?utf8=✓&q=+conditional+conformances |
This is now implemented on master branch using Swift 4.1 conditional conformances. Finally 🚀 |
Is there any reason why the array extension of JSONDecodable is commented since the last update? https://github.com/MLSDev/TRON/blob/master/Source/SwiftyJSON/SwiftyJSONDecodable.swift#L58
The text was updated successfully, but these errors were encountered: