nscopying

How do copy and mutableCopy apply to NSArray and NSMutableArray?

只谈情不闲聊 提交于 2019-11-26 19:30:30
What is the difference between copy and mutableCopy when used on either an NSArray or an NSMutableArray ? This is my understanding; is it correct? // ** NSArray ** NSArray *myArray_imu = [NSArray arrayWithObjects:@"abc", @"def", nil]; // No copy, increments retain count, result is immutable NSArray *myArray_imuCopy = [myArray_imu copy]; // Copys object, result is mutable NSArray *myArray_imuMuta = [myArray_imu mutableCopy]; // Both must be released later // ** NSMutableArray ** NSMutableArray *myArray_mut = [NSMutableArray arrayWithObjects:@"A", @"B", nil]; // Copys object, result is immutable

How do copy and mutableCopy apply to NSArray and NSMutableArray?

蓝咒 提交于 2019-11-26 06:58:59
问题 What is the difference between copy and mutableCopy when used on either an NSArray or an NSMutableArray ? This is my understanding; is it correct? // ** NSArray ** NSArray *myArray_imu = [NSArray arrayWithObjects:@\"abc\", @\"def\", nil]; // No copy, increments retain count, result is immutable NSArray *myArray_imuCopy = [myArray_imu copy]; // Copys object, result is mutable NSArray *myArray_imuMuta = [myArray_imu mutableCopy]; // Both must be released later // ** NSMutableArray **