user1834305
user1834305

Reputation:

Arc and nilling property through weak pointer

I have a situation here where I would want to nil a strong property with a weak reference property. My class looks like this;

@interface MyClass()
@property(nonatomic, strong) Man *man;
@property(nonatomic, strong) Women *women;
@property(nonatomic, weak) Person *passedPerson
@end

I pass this object everytime to the new view controller, sometimes I pass men while some time I pass women but I always keep track of the passed object in weak reference, ie. passedPerson. Now, when the viewcontroller return, based on the currently passed object, I would like to nil it through the weak reference pointer. Is it even possible ? This is not my exact situation but I have many objects like this which needs to be nilled out when I finish with them in the presenting view controller. How can this be done ?

Upvotes: 1

Views: 211

Answers (1)

David
David

Reputation: 9945

Weak reference is used when you need to break a reference cycle. In the example you show, there is no reference cycle. But I assume you want to keep the passedPerson.

You could use weak references to man and women and keep a strong reference on the passedPerson. Then you can nil out the passedPerson as you are finished with them.

Upvotes: 1

Related Questions