In general, there are two broad categories: collection class and non-collection class
Concept: pointer copy commonly known as pointer Copy, object copy is commonly known as content copy;
1, non-collection of deep-type copies such as: NSString, nsnumber, etc.;
The following print is the address result:
It is obvious that Stringh and Stringw address, and STRINGQ address is not the same, the STRINGW is done is a shallow copy (pointer copy), and Stringq is a deep copy (content copy);
Again such as:
The following print is the address result:
Four addresses are all different, and as long as copy, can not be modified; The address is not the same as the complete is a deep copy (content copy);
2, sets of the depth of the copy of the class: such as Nsarray, nsdictionary, etc.;
Https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Collections/Articles/Copying.html
The copy of the collection class and the amazing similarity of the non-collection are just a little bit different; in fact, the so-called deep copy is a bit controversial, but enough for us to use, to really realize deep copy or use the Apple official API mentioned method:
Nsarray *deepcopyarray=[[nsarray alloc] Initwitharray:somearray Copyitems:yes];
OR archive:
nsarray* Truedeepcopyarray = [Nskeyedunarchiver unarchiveobjectwithdata:[nskeyedarchiver archivedDataWithRootObject : Oldarray]];
Compiler has been a problem, crash all, first write to this, the level of limited inevitably have flaws, welcome correction!
Deep copy and shallow copy of IOS