ObjectForKey和ValueForKey的区别-ForKey?.之间的区别是什么?objectForKey和valueForKey?我查阅了这两份文件,它们在我看来是一样的。
3 回答
萧十郎
TA贡献1815条经验 获得超12个赞
objectForKey:
:(id)aKey
valueForKey:
:(NSString *)key
.
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSArray arrayWithObject:@"123"],[NSNumber numberWithInteger:5], nil]; NSLog(@"objectForKey : --- %@",[dict objectForKey:[NSNumber numberWithInteger:5]]); //This will work fine and prints ( 123 ) NSLog(@"valueForKey : --- %@",[dict valueForKey:[NSNumber numberWithInteger:5]]); //it gives warning "Incompatible pointer types sending 'NSNumber *' to parameter of type 'NSString *'" ---- This will crash on runtime.
valueForKey:
objectForKey:
objectForKey
- 3 回答
- 0 关注
- 866 浏览
添加回答
举报
0/150
提交
取消