0
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的dealloced,如果深拷貝,爲什麼原來的對象有新對象的效果?initWithArray:(NSArray的*)陣列copyItems:(BOOL)標誌
NSLog(@"array %@ ", arrayDeepCopy);
what initWithArray:(NSArray *)array copyItems:(BOOL)flag do after all??
你需要更好地解釋你的問題。請不要只將代碼粘貼到評論中。這些很容易被忽略。用例子問一個問題,請閱讀[faq]和[about] – Liam 2013-05-09 07:33:40