Alex Rivera | Logout

Make unique NSMutableArray or NSMutableSet

Asked 2009-07-21T18:29:55.817
16

I'm currently enumerating through NSMutableArray (or NSMutableSet) elements to find duplicates and remove them.

For example, if array/set has values [@"a", @"b", @"b", @"c"], the end result should be [@"a", @"b", @"c"].

Since I'm comparing NSStrings, I'm using isEqualTo: method to check if strings are equal.

Is there a more efficient way to do remove duplicate entries than to loop through all of them and check if duplicate exists?

Edit
Report

1 Answer

1

Only this line of code will work fine .

NSSet *mySet = [NSSet setWithArray:myArray];

now mySet will have unique elements.

answered 2013-04-09T12:15:33.757

Your Answer