开发者

iphone: What is the difference between setObject:forKey: and setValue:forKey: in Adding Entries to a Mutable Dictionary [duplicate]

开发者 https://www.devze.com 2023-03-08 18:56 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Where's the difference between setObject:forKey: and setValue:forKey: in NSMutableDictionary?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Where's the difference between setObject:forKey: and setValue:forKey: in NSMutableDictionary?

Hi,

setObject:forKey:

Adds a given key-value pair to the dictionary.

- (void)setObject:(id)开发者_开发问答anObject forKey:(id)aKey

Again

setValue:forKey:

Adds a given key-value pair to the dictionary.

- (void)setValue:(id)value forKey:(NSString *)key

Then what is the difference in between them? Is the difference only in receiving parameters? can setObject:forKey: be used instead of setValue:forKey: ?


From the doc:

setValue:forKey:

Discussion
This method adds value and key to the dictionary using setObject:forKey:, unless value is nil in which case the method instead attempts to remove key using removeObjectForKey:.

setObject:forKey:

Important
Raises an NSInvalidArgumentException if aKey or anObject is nil. If you need to represent a nil value in the dictionary, use NSNull.

If aKey already exists in the dictionary, the dictionary’s previous value object for that key is sent a release message and anObject takes its place.

0

精彩评论

暂无评论...
验证码 换一张
取 消