An introduction to the properties of @property methods in iOS programming is very concise and straightforward, and the original link is to be stamped.
= = = Read after split line = =
After iOS 5, with the advent of arc, there was no need for manual memory management, and there were some changes in the properties of the @property.
It is often used as follows:
| Property |
function Introduction |
| Getter= |
Give Getter Method a custom name |
| Setter= |
Give setter method a custom name |
| ReadOnly |
Do not generate setter methods |
| Nonatomic |
Prohibit multi-threading, which improves performance compared to default thread protection (atomic) |
| Memory Management Properties |
|
| Weak |
Weak reference, the declared variable has no ownership of the object and prevents retain cycle |
| Strong |
Strong reference, the declared variable holds ownership of the object |
| Copy |
Create and reference a copy of an Assignment object |
Copy property:
Can be used to override the strong property. It is best to declare variables (values) instead of connections or relationships.
In the Car.h:
@property (nonatomic, copy) NSString *model;
Car *honda =[[Car alloc] init]; Nsmutablestring*tmp = [nsmutablestring stringwithstring:@"Honda"]; Honda.model=tmp; NSLog (@"%@", Honda.model);//Honda[tmp setString:@ "Nissa"]; NSLog (@"%@", Honda.model);//Honda
When the variable property is copy, the change of the TMP value does not change the value of Honda.model, and the Honda.model value under the Strong\weak property changes.
Weak properties:
Delegate and outlet apply the weak attribute to declare.
Other Properties (deprecated in development after iOS 5):
Retain
unsafe_unretained
Assign