Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setter and getter for an atomic property

Tags:

what's the auto-gen'd getter and setter look like for the following property value?

... in .h @interface MyClass : NSObject { @private     NSString *_value; }  @property(retain) NSString *value;  ... in .m @synthesize value = _value; 

what if I change the property to be

@property(retain, readonly) NSString *value; 

specifically I am interested in the atomic part of the story, plus the retain, and if possible, detailed code would be more clear as to what's going exactly going on behind the scene.

like image 264
tom Avatar asked Dec 05 '11 08:12

tom


People also ask

What is getter and setter properties?

What are Getters and Setters? Getters: These are the methods used in Object-Oriented Programming (OOPS) which helps to access the private attributes from a class. Setters: These are the methods used in OOPS feature which helps to set the value to private attributes in a class.

What does atomic property mean?

The electrons associated with atoms are found to have measurable properties which exhibit quantization. The electrons are normally found in quantized energy states of the lowest possible energy for the atom, called ground states.


1 Answers

They would look something like:

- (NSString*) value  {     @synchronized(self) {         return [[_value retain] autorelease];     } }  - (void) setValue:(NSString*)aValue {     @synchronized(self) {         [aValue retain];         [_value release];         _value = aValue;     } } 

If you change the property to readonly, no setter is generated. The getter will be identical.

like image 63
zpasternack Avatar answered Sep 27 '22 22:09

zpasternack