Since imageArray is not allocated it is set to nil. Sending messages to nil is perfectly valid in Objective C.
Insert
Code:
NSLog(@"imageArray is at %p",imageArray);
and you will see it points to 0x0 without an alloc.
Don't follow your response, about doesn't seem to do anything. You can't
-initWithCapacity until you
allocate first.
Code:
imageArray = [NSMutableArray arrayWithCapacity:16];
will allocate and initialize the array. Calling
Code:
[imageArray initWithCapacity:32];
without an alloc first does not work. It must be used in the nested
imageArray = [[NSMutableArray alloc] initWithCapacity:32];
Attempting to call it separately throws an exception, and causes a crash. The -initWithCapacity method is not and cannot be called directly by an instance of NSMutableArray. During the allocation and initialization process it is called by one of the class cluster's abstract private classes, whose public face is the NSMutableArray.
Acceptable allocation and initialization would be
Code:
imageArray = [NSMutableArray arrayWithCapacity:16];
[imageArray addObject:@"P1010579.jpg"];
[imageArray addObject:@"P1010580.jpg"];
[imageArray addObject:@"P1010581.jpg"];
[imageArray addObject:@"P1010582.jpg"];
[imageArray addObject:@"P1010583.jpg"];
NSLog(@"number of objects: %d", [imageArray count]);
or
Code:
imageArray = [[NSMutableArray alloc] init];
[imageArray addObject:@"P1010579.jpg"];
[imageArray addObject:@"P1010580.jpg"];
[imageArray addObject:@"P1010581.jpg"];
[imageArray addObject:@"P1010582.jpg"];
[imageArray addObject:@"P1010583.jpg"];
NSLog(@"number of objects: %d", [imageArray count]);
or
Code:
imageArray = [[NSMutableArray alloc] initWithCapacity:16];
[imageArray addObject:@"P1010579.jpg"];
[imageArray addObject:@"P1010580.jpg"];
[imageArray addObject:@"P1010581.jpg"];
[imageArray addObject:@"P1010582.jpg"];
[imageArray addObject:@"P1010583.jpg"];
NSLog(@"number of objects: %d", [imageArray count]);
Bob