An explanation of Ios property properties
property is an attribute that is added by Objective-c to automatically generate setter and Getter methods. It can not only help us to manage the memory there are some other special functions such as multithreading control, memory management.
@property keywords are divided into three categories: Atomicity, operability, memory management. Typically, the default is atomic, ReadWrite, assign, so its keywords can be set to a maximum of three.
Atomic nature:
1) atomic:atomic refers to atomic operations, meaning that only one thread can access instance variables at the same time and can be used in multithreaded operations to ensure thread safety.
2) Nonatomic:nonatomic is the opposite of atomic, which means that non-atomic operations can be accessed concurrently by multiple threads. It is faster than atomic, can not ensure thread safety, and is generally used in single threaded.
operability:
1) ReadWrite: Indicates that both read and write operations can be performed (i.e., having getter and setter methods).
2) ReadOnly: Indicates that only getter methods do not have setter methods.
Memory Management:
1) assign:assign is used for value types, such as int, float, double, nsinteger, cgfloat, etc., to represent pure replication. In addition delegate general with assign
2) Retain: A reference count plus 1 for the incoming object is required in the setter method. is to take ownership of the incoming object so that it will not be freed.
Retain declaring instance variable setter methods:
-(void) Setretainstr: (NSString *) Retainstr {
if (_RETAINSTR!=RETAINSTR) {
[_retainstr release];
_retainstr=[retainstr retain];
}
}
3) Strong:strong is an optional alternative to the retain. As retain means, the instance variable has ownership of the incoming object, which is a strong reference (strong).
4) Weak: In the setter method, the incoming object does not have a reference counter plus 1 operation that does not take ownership of the incoming object. When the object is released, the weak declares the instance variable of the township nil.
5) Copy:copy is a deep copy, which refers to the instance variable ownership of the copy of the incoming object. The original object of the modified copy does not change.
Ios-property Property Introduction