替换 NSDictionary 中的键/值
如果我有一个带有以下键/值“foo”/“bar”的字典并声明 [dictionary setObject:@"baz" forKey:@"foo"];
这会替换当前的键值与“foo”/“baz”配对并删除“foo”/“bar”?
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"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSMutableDictionary(与任何常见的哈希表一样)的行为是,如果它不存在,它会创建一个新的键/值对,如果它已经存在,它将用新值替换现有值。
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.
文档在这里;
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/Reference/Reference.html%23//apple_ref/doc/uid/TP40003692
表明会的。但请不要相信我的话,你自己读一下。
也许你还应该阅读;
http ://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Collections/Collections.html%23//apple_ref/doc/uid/10000034i
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