Shallow copy: A shallow copy is a copy of the pointer to the object, so that the pointer points to the same memory address, "Object always has only one", shallow copy makes the object reference counter +1. The code is as follows:
You can see that the pointer to the immutable string points to the same address and does not re-open the memory.
Deep copy: A deep copy is a copy of the object, preserving the value of the original object and opening up a new memory address.
In the code, declare a mutable array, add a copy-decorated property for the Wxdobject class, point the pointer to a mutable array after the implementation of the class, and print the address where the two are found to have changed. So using copy to modify a Mutable object will make a deep copy.
Retain modification: The modification of the above array is changed to retain, the object references counter +1, points to the same address, and does not re-open the memory address.
Summarize:
Retain: Reference counter +1, point to the same address. The result is just like a shallow copy, which simply makes the object's reference counter increment by 1.
Copy: For immutable objects equivalent to retain, pointer Copy, reference counter +1. Performs a deep copy of a mutable object, equivalent to a mutablecopy, content copy.
Mutablecopy: Deep Copy re-creates a new object, but retains the value of the original object. Content copy.
The difference between deep copy, shallow copy, and retain in iOS