如何获取对象的所有关联引用的列表?
在 Objective-C 2.0 中,是否有一个运行时方法可以列出对象的所有关联引用?我有一个对象,该对象具有对本地范围中定义的变量的关联引用,并且我想确保我仍然可以访问它们以在我的 dealloc 中释放它们。
In Objective-C 2.0, is there a runtime method that lists all of an object's associative references? I have an object with associative references to variables that are defined in a local scope, and I want to make sure I can still access them to release them in my dealloc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管我不确定检索所有对象关联的方法,但我不认为您不必担心释放关联对象。苹果的文档似乎表明,当与它们关联的对象被释放时,它们会得到处理(即使用 OBJC_ASSOCIATION_RETAIN 策略的对象将相应地被释放。)
有兴趣看到一种方法不过要迭代所有关联。
Apple 文档(具体来说,“创建关联”部分)
Although I am not sure about a way to retrieve all of an object's associations, I don't believe you have to worry about releasing associated objects. Apple's docs would seem to suggest they're taken care of when the object they're associated with is deallocated (i.e. an objects using the
OBJC_ASSOCIATION_RETAIN
policy will be released accordingly.)Would be interested to see a way to iterate over all associations though.
Apple's doc (specifically, the section "Creating Associations")