Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

zippyfly

macrumors regular
Original poster
Mar 22, 2008
141
0
I've been googling around and don't really understand the attributes used for @property declarations...

Is this only applicable if I am doing multi-thread programming?

And in fact is multi-threading going to happen even if I do not explicitly write a multi-threaded program, if the application generates events that concurrently access the same instances? (I don't know how, I am just theorizing).

A related question is why is there a "retain" attribute. What I mean is, shouldn't ALL setters retain then release? Why bother to set that unless you don't want to retain before releasing, and why would you do such a thing?

Help appreciated to get me (and others googling this question) on the right track.

Thanks!
 
This article on developer.apple.com explains it nicely:

http://developer.apple.com/mac/libr...ceptual/ObjectiveC/Articles/ocProperties.html

Basically retain is for Objective-C objects, assign is for most everything else (integers, ranges, points, etc). There's also copy if you want to copy the object.

Nonatomic makes more efficient accessors but in a way that it's possible incorrect values will be set or returned if two threads try to access the same property at once. You shouldn't run into problems unless you explicitly make your program multithreaded.

For what it's worth, nonatomic seems to be preferred in most sample code I've seen, that is, if you know your programs isn't going to run into multithreading issues it's worth making the property nonatomic.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.