Replacing key/value in NSDictionary

99封情书 提交于 2019-12-08 16:02:58

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/5736605/replacing-key-value-in-nsdictionary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!