Ios copies a brand new array from the bottom.

Deep copy is only a copy of the outer layer. I need an array element that is exactly the same as the old array, but the element addresses of all child elements and child elements are not the same.
the current idea is to nest and traverse all elements, but I am not familiar with nesting, so I can"t implement it for the time being. Ask God to help me write a method.

Mar.22,2021

official documentation: Apple Documentation on copying collections

according to the documentation, there are several types of deep copies

  1. A convenient way to copy an array is to use the initWithArray:copyItems: method to set copyItems to YES

    NSArray *deepCopyArray=[[NSArray alloc] initWithArray:array copyItems:YES];
  2. use NSKeyedArchiver for archiving, then unfile, and make a deep copy

    NSArray *trueDeepCopyArray = [NSKeyedUnarchiver unarchiveObjectWithData:
              [NSKeyedArchiver archivedDataWithRootObject:oldArray]];
Menu