copy: Used to maintain a copy of the incoming value, rather than the value itself, that is, the original object full assignment to another place, reload a memory area, one place has changed the object does not affect the other place.
Assign: Simple direct assignment, which is equivalent to saying that two objects point to the same memory area, one place has changed, and the others have changed.
retain: Frees the old object, assigns the value of the old object to the input object, and then increases the index count of the input object to 1
What does that mean?
Copy actually creates an identical object, and retain is not:
such as a NSString object, the address is 0x1111, the content is @ "ABC"
Copy to another nsstring, the address is 0x2222, the content is the same, the new object retain is 1, the old object has not changed
Retain to another nsstring, the same address (set up a pointer, pointer copy), the content of course the same, the object's retain value +1
Assign address or 0x1111, content is also "ABC".
Other words
1.strong: OC Object except Nsstring\block
@property (Nonatomic,strong) nsarray *< #model #>;
2.weak: Various UI controls (but not absolute, there are controls to use the strong property, but weak must be used in Xib, because the control is strong decorated when dragged into xib)
@property (nonatomic,weak) UIButton *button;
Basic data types such as 3.assign:cgfloat,nsinteger, enumerations, structs (non-OC objects)
@property (nonatomic,assign) CGFloat < #model #>;
4.copy:
<1. Copy: An immutable copy is created (such as NSString, Nsarray, Nsdictionary)
<2. Mutablecopy: Creating a mutable copy (such as nsmutablestring, Nsmutablearray, Nsmutabledictionary)
<3. @property (nonatomic,copy) nsstring *< #model #>;
• @property the selection of memory management policies
1. Non-arc
1> copy: only for Nsstring\block
2> retain: OC object except Nsstring\block
3> Assign: Basic data type, enumeration, struct (non-OC object), when 2 objects are referenced to each other, one end with retain, one end with assign
2.arc
1> copy: only for Nsstring\block
2> Strong: OC Object except Nsstring\block
3> Weak: When 2 objects are referenced to each other, one end with strong, the other end with weak
4> assgin: Basic data type, enumeration, struct body (non-OC object)
Wen/zhenglebaby (author of Jane's book)
Original link: http://www.jianshu.com/p/97c49a57f455
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".
The difference between Assign,copy,retain in iOS and the difference between weak and strong (interview)