@property and @synthesize are paired, and you can automatically generate access methods for a class member variable. In Xcode4.5 and later versions, @synthesize can be omitted.
1.atomic and Nonatomic
Atomic: The default is the property, this property is to ensure that the program in multi-threaded situations, the compiler will automatically generate some mutex lock code, to avoid the variable read and write unsynchronized problems.
nonatomic: If the object does not need to consider multithreading, add this property, which will allow the compiler to generate a few mutually exclusive lock code, can improve efficiency.
2.readwrite and ReadOnly
ReadWrite: This property is the default and will automatically generate accessors for you.
readonly: Only getter Generation does not have setter methods.
The real value of the two properties of ReadWrite, ReadOnly, is not to provide a member variable access interface, but to control access to member variables.
3.strong and weak
Strong: Strong references, which we usually refer to, determine the survival of the object directly. If there is no reference to an object and the object no longer appears in the list, the object is freed from memory.
Weak: Weak references do not determine the survival of an object. Even if an object is held with countless weak references, it is cleared if no strong references point to it.
Strong and retain function similar, weak and assign similar, only when the object disappears after the weak will automatically turn the pointer to nil;
4.assign, copy, retain
Assign: The default type, the setter method is assigned directly, does not make any retain operation, does not change the reference count. Typically used to handle basic data types.
- Retain: Releases the old object (release), assigns the value of the old object to the new object, and then counts the new object reference to 1. I understand that as a copy of the pointer, copy the original pointer, release the contents of the object pointed to by the original pointer, and then point the pointer to the new object content.
- copy: As with the retain process, release the old values first, Copy the new object, Retaincount 1. The mechanism introduced to reduce dependency on the context. I understand a copy of the content, request a piece of space into memory, assign the original object content to it, and make its reference count 1. Pay special attention to the Copy property: the object defined with the Copy property must conform to the Nscopying protocol and must implement the-(ID) Copywithzone: (Nszone *) Zone method.
can also be used directly:
Use assign: for underlying data types (nsinteger,cgfloat) and C data types (int, float, double, char, and so on)
Using copy: On NSString
Use retain: For other nsobject and its subclasses
Introduction to @property properties in iOS development