如何监视 NSMutableArray 或 NSMutableDictionary 中所做的更改?
我注意到 NSMutableDictionary 和 NSMutableArray 的“hashcode”方法给我的哈希值是键的数量,无论 NSMutableDictionary 的值和 NSMutableArray 的对象数量如何。
基本上,我想检测 NSMutableDictionary 中的更改。我的字典包含键/值对作为字符串/NSMutableArray。如果从其任何值中添加/删除项目,我想检测字典中的更改。
如果我去计算 NSMutableArray 的哈希值(我的字典中的值),这是不可行的,因为也有可能添加不同的值并删除现有的值,在这种情况下,只需让我的项目数量将保持不变,但是哈希值应该不同。
处理字典中这种变化的最佳方法是什么?
I've noticed that the method 'hashcode' for both NSMutableDictionary and NSMutableArray is giving me the hashvalue to be the number of keys irrespective of the value for NSMutableDictionary and number of objects in case of NSMutableArray.
Basically, I want to detect the change in NSMutableDictionary. My dictionary contains key/value pairs as string/NSMutableArray. And I'want to detect the change in dictionary if an item is added/deleted from any of its values.
In case if I go for calculating hash for NSMutableArray which are the values in my dictionary, it's not feasible since there's also a possibility of a different value added and existing deleted in which case simply giving me the number of items are going to remain same but the hash should be different.
Which is the best way to handle such change in dictionary?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以保留原来的字典测试一下是否和新的一样
此处的文档
You can retain the original dictionary an test if it is equal to the new one
Docs here