The name is a bit confusing ... I will explain
I have. NSMutableArrayI fill in the objects NSMutableDictionary. What I'm trying to do is, before the dictionary object is added to the array, I need to check if any of the dictionaries contains a value equal to the identifier already set.
Example:
Step 1: the button is pressed that sets the identifier of the object to use when creating the view.
Step 2: Another button is pressed inside the specified view to save part of its contents in the dictionary, and then add the specified dictionary to the array. But if an identifier already set already exists as a value for one of the dictionary keys, do not insert this dictionary.
Here is the code I have that currently doesn't work:
-(IBAction)addToFavorites:(id)sender{
NSMutableDictionary *fav = [[NSMutableDictionary alloc] init];
[fav setObject:[NSNumber numberWithInt:anObject.anId] forKey:@"id"];
[fav setObject:@"w" forKey:@"cat"];
if ([dataManager.anArray count]==0) {
[dataManager.anArray addObject:fav];
}else {
for (int i=0; i<[dataManager.anArray count]; i++) {
if (![[[dataManager.anArray objectAtIndex:i] objectForKey:@"id"] isEqualToNumber:[NSNumber numberWithInt:anObject.anId]]) {
[dataManager.anArray addObject:fav];
}
}
}
[fav release];
}
source
share