views:

135

answers:

3

Example:

I have an class that inherits from UIImageView. An object creates an instance from that class. Now, that class needs a weak reference to it's parent. I could make an initializer where the object has to pass "self" to the new created object. But I feel that there is a better way. Is there any?

+2  A: 

I don't think there's any way to do this natively in the language.

The problem you would have with such a function even if it was available is what would occur if the "parent" object has been deallocated?

Eric Petroelje
+3  A: 

You might want to take a look at:

Basically, these questions make the same conclusions as are made here: there is no built in way. You'll need to reference yourself, like

-(id)initWithParent:(id)parent
Kriem
+2  A: 

No, there's not. If you need this you'll have to set the parent during or right after initialization.

Marc Charbonneau