1. 程式人生 > >關於陣列的複製問題------淺拷貝,深拷貝

關於陣列的複製問題------淺拷貝,深拷貝

深度複製陣列:

 NSArray *mArray1 = [NSArray arrayWithObjects:[NSMutableString stringWithString:@"a"],@"b",@"c",nil];

    NSMutableArray *mArrayMCopy1 = [[NSMutableArray alloc] initWithArray:mArray1 copyItems:YES];

    NSLog(@"mArray1  address:%p",mArray1);

    NSLog(@"mArrayMCopy1 address:%p", mArrayMCopy1);

    NSLog(@"The first object address in mArray1:%p", [mArray1 objectAtIndex:0]);

    NSLog(@"The first object address in mArrayMCopy1:%p", [mArrayMCopy1 objectAtIndex:0]);

注意,數組裡面的物件需要實現NSCopying協議.