Thursday, 14 March 2013

To find unique elements of array from a repeated elements array.


NSArray* repeatedArray=[[NSArray alloc]init];

repeatedArray=[@"1,2,2,2,2,3,3,3,3,4,4,1,1,1,1,5,5,5,5,5,5"]; //example 

NSMutableArray *uniqueArray = [[NSMutableArray alloc]init];

    for(NSNumber *obj in repeatedArray) //NSNumber it depends on ur object type
    {
        if(![uniqueArray containsObject:obj])
        {
            [uniqueArray addObject:obj];
        }
    }

OUTPUT: uniqueArray=[1,2,3,4,5];  //THATS what we want