Question

Naturally, the keys of a NSDictionary are not ordered, and so are its values.

So, why do the allKeys and allValues methods of NSDictionary return NSArray and not NSSet?

Était-ce utile?

La solution

A value can occur more than once in a dictionary but not in a set. So returning an array returns all the values, while returning a set would return only the unique values.

Keys of course must be unique, so I'd suggest the choice of array rather than set is simple consistency.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top