NSMutableDictionary *dic0 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"string0", @"key0", nil];
NSDictionary *dic1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"string1", @"key1", nil];
NSDictionary *dic2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"string2", @"key2", nil];
NSDictionary *dic3 = [[NSDictionary alloc] initWithObjectsAndKeys:@"dic3", @"key3", nil];
NSArray *arrayOri = [[NSArray alloc] initWithObjects:dic0, dic1, dic2, nil];
//here means a deep copy
NSMutableArray *arrayDeepCopy = [[NSMutableArray alloc] initWithArray:arrayOri copyItems:YES];
NSRange range = {0, 2};
NSArray *subArray = [arrayOri subarrayWithRange:range];
[arrayDeepCopy addObject:dic3];
NSLog(@"arrayOri not merge %@", arrayOri);
//merge one object
[dic0 setObject:@"mutableV" forKey:@"mutableKey"];
//dealloc one object
[dic1 dealloc];
NSLog(@"arrayOri %@ ", arrayOri);
NSLog(@"subArray %@ ", subArray);
在这里崩溃,因为 dic1 已解除分配,如果是深拷贝,为什么原始对象对新对象有影响?
NSLog(@"array %@ ", arrayDeepCopy);
what initWithArray:(NSArray *)array copyItems:(BOOL)flag do after all??