开发者

Replacing key/value in NSDictionary

If I have a dictionary with the following key/value "foo"/"开发者_JAVA百科bar" and declared [dictionary setObject:@"baz" forKey:@"foo"]; would this replace the current key value pair with "foo"/"baz" and delete "foo"/"bar"?


The behave of an NSMutableDictionary (as any common hash table) is that if it does not exists it creates a new key/value pair, if it already exits it will replace the existing value with the new one.


The documentation here;

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/Reference/Reference.html%23//apple_ref/doc/uid/TP40003692

suggests that it would. But please, don't take my word for it, read them yourself.

Perhaps you should also read;

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Collections/Collections.html%23//apple_ref/doc/uid/10000034i

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜