Lets say I have an array X that contains [A,B,C,D,nil];
and I have a second array Y that contains [E,F,G,H,I,J,nil];
If I execute the following:
//Append y to x
[x addObjectsFromArray:y];
//Empty y and copy x
[y removeAllObjects];
y = [x mutableCopy];
What is the value of y? is it?:
[A,B,C,D,E,F,G,H,I,J,nil]
Am I performing the copy correctly?
At the end of the operation I want y to be [A,B,C,D,E,F,G,H,I,J]
At the start:
x is [A, B, C, D] (the nil is not part of the array, it just tells initWithObjects: where the end of the list of objects is).
y is [E, F, G, H, I, J]
x is [A, B, C, D, E, F, G, H, I, J]
y is [E, F, G, H, I, J]
x is [A, B, C, D, E, F, G, H, I, J]
y is []
x is [A, B, C, D, E, F, G, H, I, J]
y is [A, B, C, D, E, F, G, H, I, J]
Note that the previous version of y that you emptied may have leaked because you overwrote the pointer with a pointer to a new mutable copy of x. You should have done:
Or if you obtained y by using +arrayWithObjects: instead of +alloc followed by -initWithObjects: simply