IOS @ synthesize and @ property, iossynthesize
1. First, let's talk about @ property, which is a keyword coming out after iOS6. After declaring an attribute with it, the compiler will automatically generate the setter and getter methods for you.
@ Property (nonatomic, retain) NSString * name;
The setter method is as follows:
-(Void) setName :( NSString *) _ name {
// First, determine whether it is consistent with the old object. If it is inconsistent, assign a value.
// If it is an object, executing the code in if will cause an extreme situation: When the retain of this name is 1, this set operation allows the Instance name to be released in advance without assigning values.
If (name! = _ Name ){
[Name release];
Name = [_ name retain];
}
}
The getter method is as follows:
-(NSString *) name
{
Return _ name;
}
2. @ synthesize stated in. m
@ Synthesize name = _ name;
In this way, both self. name = otherString and name = otherString can be compiled normally, but the former calls the setter Method for a copy, and the latter does not, which is equivalent to assign/weak.