objectForKey返回指定key的value,若没有这个key返回nil
valueForKey同样是返回指定key的value
一般来说key可以是任意字符串组合,如果key不是以@符号开头,这时候valueForKey:等同于objectForKey:,如果以@开头,去掉key里的@然后用剩下部分作为key执行[super valueForKey:]。
NSDictionary *dict = [NSDictionary dictionaryWithObject:@"theValue" forKey:@"theKey"];
NSString *value1 = [dict objectForKey:@"theKey"];
NSString *value2 = [dict valueForKey:@"theKey"];
这个时候value1和value2是一样的结果。如果这样一个dict:
NSDictionary *dict = [NSDictionary dictionaryWithObject:@"theValue" forKey:@"@theKey"];
NSString *value1 = [dict objectForKey:@"@theKey"];
NSString *value2 = [dict valueForKey:@"@theKey"];