Nutshell:
1, for immutable non-collection objects, copy is a pointer copy, Mutablecopy is a copy of the content
2. Copy,mutablecopy is a content copy for mutable non-collection objects
3, for immutable arrays, dictionaries, sets and other collection class objects, copy is a pointer copy, Mutablecopy is a content copy
4, for variable arrays, dictionaries, sets and other collection class objects, copy,mutablecopy are content copies
However, the contents of the collection object are copied only to the object itself, but the elements inside the object are still copied by the pointer. To replicate the entire collection object, there are two ways to use the collection deep copy:
(1) using the Initwitharray:copyitems: method, set the second parameter to Yes
Nsdictionary shallowcopydict = [[Nsdictionary alloc] initwithdictionary:somedictionary Copyitems:yes];
(2) Archive the Collection Object (archive) and then archive (unarchive):
Nsarray *truedeepcopyarray = [Nskeyedunarchiver unarchiveobjectwithdata:[nskeyedarchiver archivedDataWithRootObject : Oldarray]];
Deep copy and shallow copy in iOS development