Search code examples
iphoneiosobjective-cios4

How to remove duplicity from array of dictionaries in IOS?


  (
    {
            color = blue;
    },
    {
            color = blue;
    },
    {
            color = red;
    },
    {
            color = white;
    }
 ) 

This is an Array of dictionary, i have to remove duplicate dictionary from array corresponding to key color.


Solution

  • NSSet is to save you in this case. Use:

    NSSet *set = [NSSet setWithArray:duplicateArray];
    NSArray *uniqueArray = [set allObjects];
    

    Avoid using loop for this because if you have more object loop is a consuming process. You can directly use NSSet and it will work for sure.