A copy of an object can be created using the copy or nutablecopy method. The original object is not affected when the copy is modified.
Copy : Must be implemented first
Nscopying Protocol ,
Creating an immutable copy (Such as nsstring, nsarray, and nsdictionary)
Mutablecopy : Must be implemented first
Nsmutablecopying Protocol ,
A mutable copy is created. (Such as nsmutablestring, nsmutablearray, and nsmutable)
Deep copy: the source object and copy point to two different objects. The Reference Counter of the object remains unchanged, and the copy counter is set to 1
Copy: pointer copy. The source object and copy point to the same object. The Reference Counter of the object is + 1, which is equivalent to a retain operation.
Only the immutable object that creates an immutable copy is the shortest copy.
Mutablecopy is also a deep copy. Nsstring * string = [[nsstring alloc] initwithformat: @ "Age is % d", 10]; nsmutablestring * STR = [String mutablecopy];
Copy generates an immutable copy. Because the source object itself is immutable, copy directly returns the source object for the sake of performance. The source object counter will be + 1 Nsstring * STR = [String Copy];
Objective-C: 12_copy