Why do the allKeys and allValues ​​NSDictionary methods return an NSArray and not an NSSet?

Naturally, the keys to are NSDictionarynot ordered, as well as its meanings.

So why methods allKeysand allValues NSDictionaryreturn NSArrayinstead NSSet?

+4
source share
1 answer

A value can be repeated more than once in a dictionary, but not in a set. Therefore, returning an array returns all values, and returning a set returns only unique values.

The keys, of course, must be unique, so I would suggest that the choice of the array, and not the set, be simple consistency.

+4
source

Source: https://habr.com/ru/post/1527072/


All Articles