Alternative to Objective-C objects in structs (ARC

2019-02-25 11:50发布

问题:

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;
}

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

回答1:

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)