Suppose I have a class Event, and it has 2 properties: action (NSString) and date (NSDate).
And suppose I have an array of Event objects. The problem is that \"date\" pr
I think the most effective way is to use NSDictionary
to store the object as value and the property value as key, and before adding any object to the dictionary you check if it exist or not which is O(1) operation, i.e. the whole process will take O(n)
Here is the code
- (NSArray *)removeDuplicatesFromArray:(NSArray *)array onProperty:(NSString *)propertyName {
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
for (int i=0; i
you can use it as the following
self.arrayWithObjects = [self removeDuplicatesFromArray:self.arrayWithObjects onProperty:@"when"];