What is the difference between the "copy" & "mutableCopy"?
EDIT_001:
My original post was a bit of a mess, partly due to a lack of understanding and partly due to a bit of pilot error on my part. Here is my attempt to better explain how "copy" & "mutableCopy" work.
// ** 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];
[myArray_imuCopy release];
[myArray_imuMuta release];
.
// ** NSMutableArray **
NSMutableArray *myArray_mut = [NSMutableArray arrayWithObjects:@"A", @"B", nil];
// Copys object, result is immutable
NSMutableArray *myArray_mutCopy = [myArray_mut copy];
// Copys object, result is mutable
NSMutableArray *myArray_mutMuta = [myArray_mut mutableCopy];
[myArray_mutCopy release];
[myArray_mutMuta release];
EDIT_002:
- mutableCopy always returns a mutable result.
- copy always returns an immutable result.
thank you for all the answers, comments ... much appreciated.
gary