我的字典查找ArrayOfDictionaries詞典與特定鍵值對
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數組的數組:@「標識」爲1或2或別的東西,像有一個SQL查詢從表其中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");
任何幫助,將不勝感激選擇*。 在此先感謝!
什麼是你的實際問題? – occulus