Is there a way to remove duplicate (key-value) pairs from NSDictionary ?
EDIT:
My description was misleading, I have duplicate pairs e.g.
key1-value1
key1-value1
key2-value2
key1-value1
etc..
Is there a way to remove duplicate (key-value) pairs from NSDictionary ?
EDIT:
My description was misleading, I have duplicate pairs e.g.
key1-value1
key1-value1
key2-value2
key1-value1
etc..
One way is to put the key/value pairs into a dictionary by value/key and then converting that back to key/value.
reversing key-value is not good idea because not all values can be keys. You can do it with:
// dict is original dictionary, newDict new dictionary withot duplicates.
yuo can also use lastObject instead of objectAtIndex:0 to leave other key for dup objects
I can't think of a built-in method.
If you iterate over the values, allKeysForObject: will give you an array of keys for each value and if you have more more than one key, that value has duplicates.