(1), assign is the direct assignment value. Reference counting issues are not involved, and are primarily used to assign values to OBJC base data types (Nsinteger, cgfloat, and so on) and C base data types (int, double, float, char, and so on).
(2), retain is a pointer copy, using the reference count, the object after the retain operation will make the object reference count +1, added a reference to the original object.
(3), copy is a value copy, after the object copy operation is equivalent to the original object made a copy. The value of the new object will be the same as the original object, but the new object and the member object each have their own memory address, that is, the memory address of the new object is different from the original object, so copy does not increment the reference count of the member object. However, the reference count for the new object is incremented to 1, which is equivalent to creating a new object that is the same as the original object.
(4), Atomic, and nonatomic are used to determine whether the getter and setter generated by the compiler are atomic operations. In a multithreaded environment, atomic operations are necessary, otherwise they may cause incorrect results. Adding the Atomic,setter function will change to the following:
- if (Property! = newvalue) {
- [Property release];
- property = [NewValue retain];
- }
Copy Code
The Nonatomic property means that multiple threads are disabled, which can effectively increase efficiency and conserve resources when an object does not need to be accessed in multiple threads.
Note: Retain cannot be used with the base data type because the base data type does not have a reference count. The Copy property is valid only for object types that implement the Nscopying protocol. When the data is a native type, such as int, float, you can use the Assign
Use of retain,assign,copy in iOS