当复制对象是可变对象的时候:copy是复制部分内容,当然也不是简单的指针复制,应该是当前类的复制;mutableCopy是深度复制,对所有内容进行的复制,测试代码如下:
NSMutableArray * muArr = [[NSMutableArray alloc] init];
[muArr addObject:@"sssssssssss"];
NSLog(@"局部可变:array:%@ retainCount:%ld address:%p size:%ld",muArr,[muArr retainCount],muArr,class_getInstanceSize([muArr class]));
NSArray * arr = [muArr copy];
NSLog(@"copy:array:%@ retainCount:%ld address:%p size:%ld",arr,[arr retainCount],arr,class_getInstanceSize([arr class]));
NSArray * mArr = [muArr mutableCopy];
NSLog(@"mucopy:array:%@ retainCount:%ld address:%p size:%ld",mArr,[mArr retainCount],mArr,class_getInstanceSize([mArr class]));
当复制对象是不可变对象的时候:copy不复制,直接指向对象;mutableCopy是深度复制,对所有内容进行的复制,测试代码如下:
NSArray * muArr = [[NSArray alloc] initWithObjects:@"sssssssss", nil];
NSLog(@"局部不可变:array:%@ retainCount:%ld address:%p size:%ld",muArr,[muArr retainCount],muArr,class_getInstanceSize([muArr class]));
NSArray * arr = [muArr copy];
NSLog(@"copy:array:%@ retainCount:%ld address:%p size:%ld",arr,[arr retainCount],arr,class_getInstanceSize([arr class]));
NSArray * mArr = [muArr mutableCopy];
NSLog(@"mucopy:array:%@ retainCount:%ld address:%p size:%ld",mArr,[mArr retainCount],mArr,class_getInstanceSize([mArr class]));