@ Property defines attributes and declares the getter and setter methods. (Note: The property is not a variable)
@ Synthesize is used to implement attributes, such as the getter and setter methods.
If you override setter, Getter, and method when declaring an attribute, You need to define the unrecognized variable in @ synthesize and apply the attribute access method to the variable. For example:
. H file
@property (nonatomic,assign)NSInteger age;@property (nonatomic,retain)NSString * name;@property (nonatomic,copy)NSString * bb;
In the. M file
// If the following three rows are not added, the system reports that the _ age, _ name, And _ BB variables cannot be found. @ synthesize age = _ age; @ synthesize name = _ name; @ synthesize BB = _ BB;-(void) setname :( nsstring *) name {If (_ name! = Name) {[_ name release]; _ name = [name retain] ;}}- (nsstring *) name {return [[_ name retain] autorelease];} -(void) setage :( nsinteger) Age {_ age = age;}-(nsinteger) Age {return _ age;}-(void) setbb :( nsstring *) bb {If (_ BB! = Bb) {[_ BB release]; _ BB = [BB copy] ;}}- (nsstring *) bb {return [[_ BB retain] autorelease];}
?
Conclusion: The difference between attributes and variables must be distinguished and cannot be confused. @ Synthesize the declared attribute = variable. It means to apply the setter and getter methods of the attribute to this variable.