I wrote a little convenience method on NSArray which works like PHP's list() function for "unpacking" an array into distinct objects:
- (void)unpackInto:(__strong id *)obj1, ...
{
__strong id *idPtr;
va_list args;
va_start(args, obj1);
idPtr = obj1;
NSUInteger idx = 0;
NSUInteger count = [self count];
while (idPtr != NULL && idx < count) {
*idPtr = [self objectAtIndex:idx];
// Increment the args and idx count
idx++;
idPtr = va_arg(args, __strong id *);
}
}
I originally had __autoreleasing id *
but ran into a EXC_BAD_ACCESS issue when this method was called (twice actually, if it matters) on a thread with it's own autorelease pool to unpack the contents into temporary local stack vars. When the main thread came around and attempted to autorelease the contents (again), EXC_BAD_ACCESS was thrown.
Can anyone help me follow the logic with these bridging parameters in this case? I'm concerned that __strong
will lead to the slightly less obvious but equally evil twin cousin: memory leak...