结构中的Objective-C对象的替代方案(ARC) [英] Alternative to Objective-C objects in structs (ARC)
问题描述
我这里有以下代码,因为它在结构中结合了Objective-C对象,因此无法在ARC上运行:
I have the following code here that won't run on ARC since it combines Objective-C objects in structs:
struct SingleToManyRelation {
id singleObject;
NSSet* manyObjects;
}
我知道这让人想起Core Data,但这不是重点;)我只是在寻找一种解决方案来实现类似的目的,而不必创建容器"类.
I know this is reminiscent of Core Data, but that's not the point ;) I am just looking for a solution to implement something like that without having to create a "container" class.
预先感谢您的建议, 基督徒
Thanks in advance for your advices, Christian
推荐答案
为对象提供__unsafe_unretained
属性,ARC将停止抱怨(但是请记住,它们没有保留!因此,您必须以某种方式存储一个强大的对象与他们的关系,如果你不想失去他们)
Give your objects the __unsafe_unretained
attribute and ARC will stop complaining (but keep in mind that they aren't retained! So you have to somehow store a strong relationship to them, if you don't want to lose them)
这篇关于结构中的Objective-C对象的替代方案(ARC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!