Code: Select all
// choose arbitrary size for array
int count = 20;
// allocate memory for array of pointers
NSString ** stringArray = (NSString **)malloc ( sizeof ( NSString *) * count );
// create objects and log them to the console
for (i = 0; i < count; i++)
{
stringArray[i] = [[NSString alloc] initWithFormat:@"String %d",(i+1)];
NSLog(@"stringArray[%d]: %@", i, stringArray[i]);
}
// release objects
NSString * theString;
for (i = 0; i < count; i++)
{
theString = stringArray[i];
[theString release];
}
// free malloc'd memory
free (stringArray);
Also worth looking at NSArray's -getObjects:
- Scott