tags:

views:

33

answers:

2

When to use attributes and What is the purpose of each attribute?

+1  A: 

I think it's hard to give more thorough answer then you can find in docs

Vladimir
I raised this Question after reading that documentation. It is making me mad.
muthukumar
Then you should be more specific in your question - what exactly you don't understand
Vladimir
Using copy:A new instance is created, the former is released. Using retain@property (retain) NSString *string;is equivalent to-(void)setString:(NSString *)newString {if (string != newString) {[string release];string = [newString retain];}}What is the difference btw those two?
muthukumar
When copy attribute is used then normally a copy of the object is assigned to iVar - so iVar is not equal to the object you pass to setter (there're exceptions - for example NSString optimizes copying to retaining). If retain is used then iVar points to the same object as setter parameter.
Vladimir
A: 

Some attributes:

readonly - use if you don't want a setter

retain - use if you want values assigned to your property to be retained

copy - use if you want values assigned to your property to be copied.

assign - use if you want new values to be assigned with no retain or copy.

nonatomic - use to disable the mechanism that makes property access atomic. An atomic property is guaranteed to give you a pointer to a real object that still exists or nil. In a multithreaded environment, a nonatomic property could give you an object that has already been deallocated.

JeremyP