I've been wondering how to do backwards relationships with readonly properties. Lets say there's a parent class:
@interface Parent
@property (strong, readonly) Child * child;
@end
And a child
@interface Child
@property (weak, readonly) Parent * parent;
@end
The problem is that both need the other to have already been initialised, and after that the property is readonly. This first came up when looking into Apple's documentation and seeing it being applied in CBCharacteristic
. How do they do that?
Edit: to make it clear I'm not talking about inheritance! Maybe that was a poor choice of a name. This is what I want:
Parent * parent = [Parent new];
Child * child = [Child new];
parent.child = child;
child.parent = parent;
This is a cyclic relationship!
I just came up with this:
Parent * parent = [Parent alloc];
Child * child = [Child alloc];
parent = [parent initWithChild:child];
child = [child initWithParent:parent];
It should OK, no?
Edit: never mind that last edit. Please see the comments below.