[objective_c] Collections support for NS[Mutable]Dictionary
and NS[Mutable]Set
#2234
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NSDictionary
andNSMutableDictionary
now mix inMapBase
, andNSSet
andNSMutableSet
mix inSetBase
. The immutable variants just throw if the mutating methods are called.The implementation is mostly straightforward. To make iteration easier, I also changed
NSEnumerator
to implementIterator
. That way, we can use the existing[key/object]Enumerator()
methods to iterate the collections without having to add another layer of wrapping.The one quirk is that
NS[Mutable]Dictionary
's keys must implement theNSCopying
protocol, which means that on the Dart side we have a bunch ofNSCopying
objects in the API, instead of pureObjCObjectBase
. But the ObjC API isn't very type safe, so there are still a bunch of places where it usesObjCObjectBase
for the keys. So I had to do somecastFrom
calls, and add a_NSDictionaryKeyIterator
that wraps theNSEnumerator
and casts the elements as it's iterating.Also, it turns out if a class extends
Base
and mixes inMixin
, the methods fromMixin
will override any matching methods fromBase
. This means some of the methods onNSMutableArray
were falling back to the slow versions onListMixin
, rather than using the fast versions fromNSArray
. So I had to duplicate some methods. Same logic applies toNSMutableDictionary
andNSMutableSet
.Fixes #1444
Part of #1443