Is this the correct way to pop objects off the front of an array. I was just curious as I was thinking there might be a method for NSMutableArray that returned a retained object. Just curious if I am getting this right?
// PUTTING OBJECTS IN
NSMutableArray *fgStore = [[NSMutableArray alloc] init];
for(int counter=1; counter<=5; counter++) {
NSString *dataValue = [[NSString alloc] initWithFormat:@"DATA%d", counter];
[fgStore addObject:dataValue];
[dataValue release];
}
// TAKING OBJECTS OUT
NSString *saveMe = [[fgStore objectAtIndex:0] retain];
[fgStore removeObjectAtIndex:0];
NSLog(@"SAVE: %@", saveMe);
...
...
[fgStore release];
[saveMe release];
gary
This is exactly the way I would do it, I don’t think there’s another. By returning a retained object you would break one of the main rules of Cocoa memory management: Most of the time you only own the objects returned by
init…methods and have to retain the rest.