What does nonatomic and retain do in Objective-C?

Joined
Feb 21, 2011
Messages
22
Reaction score
0
Points
1
Your Mac's Specs
Macbook Air 11", 64 GB, Intel core i5, 1.6 GHz, OSX Lion 10.7
Hello every1

In objective-c when we apply synthesize accessor method or when we write property, we also use 2 terms, they are: nonatomic and retain. the syntax is given below:

@property(nonatomic, retain)

I would like to know what exactly nonatomic and retain do.
Please guide
reply soon..

Thanks
Prateek
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
Both are discussed here in The Objective-C Programming Language. Search that document for those two words.

In short...

The nonatomic directive means no locking of the variable is done during access. This speeds up access. In a multithreading scenario that could be a bad thing.

The retain directive means that upon assignment, the object will be retained. If you override the properties setter method, I believe you are then responsible for the retain.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top