The role of @property is to define properties and declare Getter,setter methods. ( Note: property is not a variable )
The role of @synthesize is to implement attributes, such as the Getter,setter method.
In the case of declaring a property, if you override the Setter,getter method, you need to define the unrecognized variable in @synthesize and use the accessor method of the property for the variable. Such as:
The. h file
@property (nonatomic,assign) Nsinteger age;
@property (nonatomic,retain) nsstring * name;
@property (nonatomic,copy) nsstring * BB;
In the. m file
If you do not add the following three lines, the report will not find the _AGE,_NAME,_BB variable error
@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];
}
Summary: Be sure to distinguish between attributes and variables, not confused. @synthesize the declared property = variable. This means that the Setter,getter method of the property acts on this variable.
The meaning and misunderstanding of @property @synthesize