mapper
mapper copied to clipboard
Use of NSDictionary and NSArray in Mappable protocol
The Mappable protocol uses NSDictionary and NSArray in its convenience methods.
public static func from(_ JSON: NSDictionary) -> Self?
public static func from(_ JSON: NSArray) -> [Self]?
Since Swift continues to move away from Objective C with 3.0, I would propose to change the types to [String: Any] and [Any]/[[String: Any]] so it integrates more naturally in Swift development. Or is there any good reason to prefer NSDictionary/NSArray over these?
Thanks for bringing this up! We have had the same conversation and the (tentative) plan is to move away from NSDictionary/NSArray in favor of the Swift equivalents. I can't provide a timeline unfortunately, but it will likely be part of the final Swift 3 release.
Thanks for your reply! I also think it is a good idea to schedule it with the Swift 3 release, since Swift 3 introduces a lot of breaking changes anyway.
@mergesort can you remind me what issue you were seeing because of this?
It wasn't an issue so much as annoyance that have to cast try T.from(JSON as NSDictionary) when parsing a response. I'd mentioned that I was going to try it out to make sure it was just as simple as that, and it indeed is, everything parses find when adding as NSDictionary.
That said, I'm never going to say no to a pure Swift solution. 😄
The one thing currently stopping us from doing this is that the last time we checked (with Swift 1.0) the cost for bridging was significant. We'll have to do some simple benchmarks to see if this is still the case. If that is no longer a problem we will definitely change them!
Any update regarding this?
Contributions welcome!