搜索NSDrray的NSArray [英] Search NSArray of NSDictionaries
问题描述
我有一个带字典的数组,
,需要通过数组搜索
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];
}
所以现在我需要更改密钥X和Y的值字典
so now I need to change the value for the key X and Y in the dictionary with
键:Name = easySprite
所以需要找到特定的字典[其他字典对名称有不同的值]
key: Name = easySprite so need to find that specific dictionary [other dictionaries have different values for Name]
我该怎么办呢?
谢谢!
推荐答案
执行以下操作以获取匹配的词典,
Do the following to get the matched dictionaries,
NSPredicate *p = [NSPredicate predicateWithFormat:@"Name = %@", @"easySprite"];
NSArray *matchedDicts = [bloquesArray filteredArrayUsingPredicate:p];
现在 matchedDicts 包含值为 @的字典easySprite用于键 @名称。从那里做其余的事情(改变X和Y)。
Now the matchedDicts contains the dictionaries with the value @"easySprite" for the key @"Name". Do the rest(changing the X and Y) from there.
这篇关于搜索NSDrray的NSArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!