我有一系列字典
for(int i = 0; i < 5; i++) {
NSMutableDictionary *_myDictionary = [NSMutableDictionary dictionary];
[_myDictionary setObject:[NSString stringWithFormat:@"%d",i] forKey:@"id"];
[_myDictionary setObject:label.text @"Name"];
[_myDictionary setObject:label1.text @"Contact"];
[_myDictionary setObject:label2.text @"Gender"];
}
[_myArray addObject:_myDictionary];
现在我想从 objectForKey:@"id" 为 1 或 2 的数组中选择一个字典,或者其他类似的 sql 查询 Select * from Table where id = 2。我知道这个过程
int index = [_myArray count];
for(int i = 0; i < 5; i++)
{
NSMutableDictionary *_myDictionary = [NSMutableDictionary dictionaryWithDictionary:[_myArray objectAtIndex:i]];
if([[_myDictionary objectForKey:@"id"] isEqualToString:id])
{
index = i;
return;
}
}
if(index != [_myArray count])
NSLog(@"index found - %i",index);
else
NSLog(@"index not found");
任何帮助,将不胜感激。提前致谢 !!!