我创建了一个字典,并在字典中设置名称键值数据,并在数组中添加字典,使用 for 循环迭代数据。但我想搜索名称为 vinod.below 的关键名字。下面是我的代码。
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");
}
}
提前致谢