简体   繁体   中英

How can I make a weak reference to a parent object when using properties?

I am not sure about it. Would I do that this way?

@property(nonatomic) MyParentObject *parentObject;

Note that I just left out the retain Keyword. Or would I have to write the Setter by myself?

Instead of retain , you can use the assign attribute (which is actually the default). assign will prevent your generated setter from retaining or releasing parentObject . For example:

@property (assign, nonatomic) MyParentObject *parentObject;

For a list of all attributes that can be used by Objective-C properties, take a look at the documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM