When should I use the nonatomic, retain, readonly and readwrite properties in Objective-C?
For example:
@property(nonatomic, retain) NSObject *myObject;
If I use nonatomic and retain, does this mean that the object will be retained?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First off, I wanted to promote the comment from David Gelhar to a full answer. The modifiers
atomicandnonatomichave nothing to do with thread safety. See this question for more detail in that space.The other items you listed can be addressed relatively simply. I’ll hit them briefly and point you toward the documentation on property modifiers if you want more.
atomicvsnonatomicprimarily ensures that complete values are returned from synthesized getters and that complete values are written by synthesized setters.readwritevsreadonlydetermines whether a synthesized property has a synthesized accessor or not (readwritehas a setter and is the default,readonlydoes not).assignvsretainvscopydetermines how the synthesized accessors interact with the Objective-C memory management scheme.assignis the default and simply performs a variable assignment.retainspecifies the new value should be sent-retainon assignment and the old value sent-release.copyspecifies the new value should be sent-copyon assignment and the old value sent-release.