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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With