标签:
1 setValue: forKey:的定义
@interface NSMutableDictionary(NSKeyValueCoding)
/* Send -setObject:forKey: to the receiver, unless the value is nil, in which case send -removeObject:forKey:.
*/
- (void)setValue:(id)value forKey:(NSString *)key;
@end
value 为 nil ,调用 removeObject:forKey:
value不为nil时调用 setObject:forKey:
key为NSString类型。
2 setObject:forKey:的定义
@interface NSMutableDictionary : NSDictionary
- (void)removeObjectForKey:(id)aKey;
- (void)setObject:(id)anObject forKey:(id <NSCopying>)aKey;
@end
anobject不能为nil,而且key是一个id类型,不仅限于NSString类型
两者的区别:
(1)setObject:forkey:中value是不能够为nil的;setValue:forKey:中value能够为nil,但是当value为nil的时候,会自动调用removeObject:forKey方法
(2)setValue:forKey:中key只能够是NSString类型,而setObject:forKey:的可以是任何类型
setValue:forKey:和 setObjectforKey: 区别
标签:
原文地址:http://www.cnblogs.com/itsApe/p/5110673.html