-(void) copydemo{//In a non-collection class object: Copy the Immutable object, copy the pointer, copy the contents of the mutablecopy operation, and copy and mutablecopy the Mutable object as content replication. The code is simply represented as follows:// //[immutableobject Copy]//Shallow Copy//[Immutableobject mutablecopy]//Deep Copy//[mutableobject Copy]//Deep Copy//[Mutableobject mutablecopy]//Deep Copy//In the collection class object, copy the immutable object, which is the pointer copy, the mutablecopy is the content copy, and the copy and Mutablecopy of the Mutable object are content replication. However: the content copy of the collection object is limited to the object itself, and the object element is still a pointer copy. The code is simply represented as follows:// //[immutableobject Copy]//Shallow Copy//[Immutableobject mutablecopy]//single layer deep copy//[mutableobject Copy]//single layer deep copy//[Mutableobject mutablecopy]//single layer deep copy//Baby *baby = [[Baby alloc] init];//The copy method must be implemented//baby.babyname = @ "Wei";nsmutabledictionary*dic = [[Nsmutabledictionary alloc] Initwithcapacity:Ten]; [DiC setobject:@"1"Forkey:@"Key1"]; Nsmutablearray*array1 =[[Nsmutablearray alloc] initwithobjects:dic,dic, nil]; Nsmutablearray*array2 = [Array1 mutablecopy];//single layer deep copyNsmutablearray *array3 = [[Nsmutablearray alloc] Initwitharray:array1 Copyitems:yes];//the dic becomes immutable.nsmutablearray* Array4 =[Nskeyedunarchiver unarchiveobjectwithdata: [Nskeyedarchiver archiveddatawithrootobj Ect:array1]];//inside the dic change does not affect other arrays (which and methods affect other arrays)[Array2 Removeobjectatindex:0]; [[Array4 Objectatindex:0] SetObject:@"3"Forkey:@"Key1"];//[[Array4 objectatindex:1] setbabyname:@ "8888"];DLog (@"%@ \%@ \%@ \%@", Array1,array2,array3,array4);}
IOS depth Copy