What does “nonatomic” mean in this code?
@property(nonatomic, retain) UITextField *theUsersName;
What is the difference between atomic and nonatomic?
Thanks
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.
Take a look at the Apple Docs.
Basically, if you say
nonatomic, and you generate the accessors using@synthesize, then if multiple threads try to change/read the property at once, badness can happen. You can get partially-written values or over-released/retained objects, which can easily lead to crashes. (This is potentially a lot faster than an atomic accessor, though.)If you use the default (which is
atomic; there used to be no keyword for this, but there is now), then the@synthesized methods use an object-level lock to ensure that multiple reads/writes to a single property are serialized. As the Apple docs point out, this doesn’t mean the whole object is thread-safe, but the individual property reads/writes are.Of course, if you implement your own accessors rather than using
@synthesize, I think these declarations do nothing except express your intent as to whether the property is implemented in a threadsafe manner.