mapper icon indicating copy to clipboard operation
mapper copied to clipboard

Use of NSDictionary and NSArray in Mappable protocol

Open wdominik opened this issue 9 years ago • 7 comments

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?

wdominik avatar Sep 21 '16 23:09 wdominik

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.

sberrevoets avatar Sep 22 '16 03:09 sberrevoets

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.

wdominik avatar Sep 22 '16 18:09 wdominik

@mergesort can you remind me what issue you were seeing because of this?

keith avatar Sep 24 '16 15:09 keith

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. 😄

mergesort avatar Sep 24 '16 15:09 mergesort

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!

keith avatar Oct 09 '16 23:10 keith

Any update regarding this?

aabanaag avatar Oct 05 '18 09:10 aabanaag

Contributions welcome!

keith avatar Oct 24 '19 22:10 keith