When you use @property to define a property, you can also add some additional prompts between @property and types with parentheses, and special indicators that you can use are as follows
· Assign: The indicator specifies that the property is simply assigned, and does not change the count of references to the assigned value. This indicator is mainly used for basic types such as Nsinteger, as well as various C data types such as short, float, double, struct, and so on.
Tip: The reference count is the concept of objective-c memory recycling, when an object's reference count is greater than 0 o'clock, indicating that the object should not be recycled, due to basic types such as Nsinteger, and short, float, double, There are no recycling problems with various C data types such as structs, so use assign.
· Atomic (nonatomic): Specifies whether the access method of the composition is an atomic operation. The so-called atomic operation, mainly refers to whether thread safety. If the use of atomic, then the composition of the storage and fetching methods are thread-safe-when a thread into the method of storage, fetch method body, the other thread can not enter the method, so that the multi-threaded concurrency to destroy the integrity of the object data, atomic is the default value. While atomic can guarantee the integrity of the object data, atomic's thread safety causes performance degradation, so in most single-threaded environments, we will consider using nonatomic to improve access performance for access methods.
· Copy: If you use the copy indicator, when you call the setter method to assign a value to a member variable, the object that is assigned is copied with a copy, and the copy is assigned to the member variable. The copy indicator will subtract 1 from the reference count of the object referenced by the original member variable. When the type of a member variable is a mutable type, or if its subclass is a mutable type, the assigned object may be modified after the assignment, and if the program does not need this modification to affect the value of the member variable set by the setter method, consider using the copy indicator.
· Getter, setter: These two indicators are used to specify a custom method name for a synthetic getter method, setter method. For example, GETTER=ABC specifies the getter method named Abc;setter=xyz: (So the setter method takes parameters, do not forget the colon), the method named the setter method is called XYZ:.
· ReadOnly, readwrite:readonly indicates that the system only synthesizes getter methods, no longer synthesize setter methods, Readwrites is the default value, indicating that the system needs to synthesize setter, getter method.
· Retain: When a property is defined with the retain indicator, when a property is assigned to that property, the reference count of the object referenced by the property is reduced by 1, and the reference count of the assigned object is added to the value 1.
Tip: Without the ARC mechanism enabled, retain is a useful indicator: When an object's reference count is greater than 1 o'clock, the object should not be recycled, but after the arc mechanism is enabled, the retain indicator is generally less used.
· The strong, Weak:strong indicator specifies that the property holds a strong reference to the assigned object, and the weak indicator specifies that the property holds a weak reference to the assigned object. A strong reference means that the object is not automatically reclaimed as long as the strong reference points to the object being assigned, and the weak reference means that the object may be recycled even if the weak reference points to the object being assigned to the value.
Tip: When starting the arc mechanism, it is convenient to use the strong, weak indicator. If the program does not want the object referenced by this property to be recycled, then the strong indicator should be used, and if the program needs to guarantee performance and avoid memory overflow, you can use the weak indicator. You need to be careful when using the weak indicator that the object may have been reclaimed when the program accesses the referenced object through the weak property. For a pointer declared as weak, the pointer to the address once disposed, these pointers will be assigned a value of nil. This can effectively prevent dangling pointers. The weak indicator effectively helps us to prevent dangling pointers.
unsafe_unretained: This indicator is basically similar to the weak indicator for only unsafe_ Unretained the object pointed to by the pointer, the object may also be recycled. Unlike the weak pointer, when the object referenced by the unsafe_unretained pointer is reclaimed, the unsafe_unretained pointer is not assigned nil, so this can cause the program to crash. In general, using the unsafe_unretained indicator is not as good as using the weak indicator.