Is this a convenient way for swapping two ivar arrays in objective C?
- (void) foo {
NSArray *aux;
aux = array1;
array2 = array1;
array1 = array2;
}
Are there any alternatives? May it have problems related to retainCount under some circumstances?
I am confused because in the program that I am reviewing the swap is done by:
- (void) foo {
NSArray *aux;
aux = array1;
[aux retain];
array2 = array1;
array1 = array2;
[aux release];
}
In your example, you’re swapping just the pointers. And by the way, you’re doing
it wrong:
If you have properties on those arrays, I’d recommend going with it: