我目前所拥有的是
NSArray * keys = [NSArray arrayWithObjects:@“firstName”,@“lastName”,@“phoneNumber”,@“email”,@“password”,nil];
NSArray * objects = [NSArray arrayWithObjects:@“nil”,@“nil”,@“nil”,@“nil”,@“abc”,nil];
dictionary = [NSDictionary dictionaryWithObject:objects forKey:keys];
NSLog(@“pass is%@”,[keys objectAtIndex:4]);
NSLog(@“pass of pass is%@”,[dictionary objectForKey:@“password”]);
但是,我从调试器得到的是
传递密码
pass的值是(null)
任何人都可以解释为什么值为null。它应该是abc,不应该。
答案 0 :(得分:2)
以下行会发出警告:
dictionary = [NSDictionary dictionaryWithObject:objects forKey:keys];
应该是:
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
答案 1 :(得分:1)
更改您缺少的这一行s
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
答案 2 :(得分:0)
你可以在下面做的也是......
NSMutableDictionary *dictionary=[NSMutableDictionary dictionaryWithObjectsAndKeys:@"nil",@"firstName",@"nil",@"lastName",@"nil",@"phoneNumber",@"nil",@"email",@"abc",@"password", nil];
NSLog(@"value of pass is%@",[dictionary objectForKey:@"password"]);