What is the functional difference between these 3?
Answer :-
The last two are identical;
With
In
Below are some examples of what is actually happening in atomic & nonatomic
Atomic :
nonatomic :
@property(nonatomic, retain) UITextField *userName;
@property(atomic, retain) UITextField *userName;
@property(retain) UITextField *userName;Answer :-
The last two are identical;
atomic is the default behavior.With
atomic, the synthesized setter/getter will ensure that a whole value is always returned from the getter or set by the setter, regardless of setter activity on any other thread. That is, if thread A is in the middle of the getter while thread B calls the setter, an actual viable value -- an autoreleased object, most likely -- will be returned to the caller in A.| Atomic guarantees that access to the property will be performed in an atomic manner. E.g. it will be thread safe, any get/set of a property on one thread must complete before another can access it. |
In
nonatomic, no such guarantees are made. Thus, nonatomic is considerably faster than atomic.Below are some examples of what is actually happening in atomic & nonatomic
Atomic :
//@property(retain) UITextField *userName;
//Generates roughly
- (UITextField *) userName {
UITextField *retval = nil;
@synchronized(self) {
retval = [[userName retain] autorelease];
}
return retval;
}
- (void) setUserName:(UITextField *)userName_ {
@synchronized(self) {
[userName_ retain];
[userName release];
userName = userName_;
}
}
nonatomic :
//@property(nonatomic, retain) UITextField *userName;
//Generates roughly
- (UITextField *) userName {
return userName;
}
- (void) setUserName:(UITextField *)userName_ {
[userName_ retain];
[userName release];
userName = userName_;
}




