I have an array with dictionaries, and need to search trough the array
and modify a specific dictionary in the array found by an object name inside the dictionary.
So , create the mutable array, dictionary , and add many dictionaries to the array
...{ self.bloquesArray = [[[NSMutableArray alloc] init]autorelease];
[self createBloqueDicto];
[self.unBloqueDicto setObject:@"easySprite" forKey:@"Name"];
[self.unBloqueDicto setObject:@"290" forKey:@"X"];
[self.unBloqueDicto setObject:@"300" forKey:@"Y"];
[self.bloquesArray addObject:self.unBloqueDicto];
}
- (void)createBloqueDicto {
self.unBloqueDicto = [[[NSMutableDictionary alloc] init] autorelease];
}
so now I need to change the value for the key X and Y in the dictionary with
key: Name = easySprite so need to find that specific dictionary [other dictionaries have different values for Name]
how can I do this please?
thanks!
Do the following to get the matched dictionaries,
NSPredicate *p = [NSPredicate predicateWithFormat:@"Name = %@", @"easySprite"];
NSArray *matchedDicts = [bloquesArray filteredArrayUsingPredicate:p];
Now the matchedDicts contains the dictionaries with the value @"easySprite" for the key @"Name". Do the rest(changing the X and Y) from there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With