@property and @synthesize
First, from the perspective of translation: @property (translated to: Nature) and @synthesize (synthesis), is not much like attributes (declarations) and implementation?
1. @property
Used in @inteface.
declaration used to automatically generate setter and getter
with @property int age, you can replace the following two lines
-(void) Setage: (int) age; // Setter-(int) age; // Getter
[Email protected] (Learn only)
Used in @implementation.
implementation to automatically generate setter and getter
With @synthesize age = _age, you can replace
-(int) age{ return _age;} -(void) Setage: (int) age{ = Age ;}
3. @synthesize Details (learn only)
The member variables are accessed in the > Setter and Getter implementations _age
> If the member variable _age does not exist, a @private member variable is automatically generated _age
Member variables are accessed in the >setter and Getter implementations
> If the member variable age does not exist, it will automatically generate a @private member variable age
> If the setter method is implemented manually, the compiler will only automatically generate getter methods
> If the Getter method is implemented manually, the compiler will only automatically generate setter methods
> If the setter and getter methods are manually implemented at the same time, the compiler does not automatically generate non-existent member variables
4. @property new features (haha, use this now)
Since Xcode 4.x, the @property has @synthesize functionality. In other words,@property can generate both a setter and a getter declaration and implementation
By default, implementations in the setter and Getter methods go to the member variables that begin with the underscore _
iOS development OC (vii)[email protected] and @synthesize