1

When you look at some Objective-C code, you often see class properties defined as non-atomic. Why? Does it give you some performance boost when you're not working with threads, or is there some other reason?

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
Jakub Lédl
  • 1,805
  • 3
  • 17
  • 26
  • possible duplicate of [Objective-C properties: atomic vs nonatomic](http://stackoverflow.com/questions/588866/objective-c-properties-atomic-vs-nonatomic) – bbum Jun 02 '10 at 22:37

1 Answers1

5

nonatomic accessors are faster because they don't have to lock. That's about all there is to it. From the documentation:

If you do not specify nonatomic, then in a reference counted environment a synthesized get accessor for an object property uses a lock and retains and autoreleases the returned value—the implementation will be similar to the following:

[_internal lock]; // lock using an object-level lock
id result = [[value retain] autorelease];
[_internal unlock];
return result;

If you specify nonatomic, then a synthesized accessor for an object property simply returns the value directly.

Community
  • 1
  • 1
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • Thanks for such a quick answer. I knew before how nonatomic properties work, I just didn't know the benefit of using them :-) – Jakub Lédl Jun 02 '10 at 18:51