对象指针值作为字典的键 [英] Object pointer value as key into dictionary
问题描述
我想将对象的参考值用作字典中的键,而不是对象值的副本.因此,我本质上想将与另一个对象的特定实例相关联的对象存储在字典中,并在以后检索该值.
I want to use the object's reference value as a key into a dictionary, as opposed to a copy of value of the object. So, I essentially want to store an object associated with a particular instance of another object in a dictionary and retrieve that value later.
这可能吗?是否完全违背NSDictionary的想法?我可以说我可能采用了错误的方式,因为字典希望我在对象本身上实现NSCopying,这对我正在做的事情实际上没有任何意义.我可以看到我真正应该做的是包装指针值,但这似乎有点疯狂.
Is this possible? Is it completely against the idea of NSDictionary? I can tell that I am probably approaching this the wrong way because the dictionary wants me to implement NSCopying on the object itself, which doesn't really make sense in terms of what I'm doing. I can see that what I should really be doing is wrapping the pointer value, but that seems a little mad.
建议将不胜感激.
推荐答案
我认为您可以使用[NSValue valueWithPointer:object]
.
这篇关于对象指针值作为字典的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!