我已經創建了一個字典,並使用for循環迭代數據,將字典和詞典中的名稱鍵值數據設置爲數組。但我想搜索名字是vinod.below的密鑰名是我的代碼。使用for循環搜索數組中的鍵
NSDictionary *dic2 =[[NSDictionary alloc] init];
NSDictionary *dic1 =[[NSDictionary alloc] init];
[dic1 setValue:@"Vinod" forKey:@"fname"];
[dic2 setValue:@"vishw" forKey:@"lname"];
[dic2 setValue:@"Tazeen" forKey:@"fname"];
[dic2 setValue:@"momin" forKey:@"lname"];
NSMutableArray *arr =[[NSMutableArray alloc] initWithObjects:dic1,dic2, nil];
NSLog(@"inside the view did load");
NSMutableArray *arr2=[[NSMutableArray alloc] init];
for (int i=0; i<[arr count]; i++)
{
NSString *str =[arr objectAtIndex:i];
NSLog(@"inside the loop");
[arr2 addObject:str];
// NSArray *arr =[[NSArray alloc] initWithObjects:str, nil];
if ([arr2 containsObject:@"vinod"])
{
NSLog(@"first name found in the array");
}
}
在此先感謝
使用NSPredicate .. –
如何通過CA你在不可變的Dictionary中添加對象嗎? –
看到我的回答.... –