What is the largest amount of objects I can put in my NSArray?
The NSArray initWithCapacity method, takes an unsigned int as an argument. So whatever the maximum value of an unsigned int is on your platform may be the theoretical limit. However the actual limit is more likely to depend on the amount of memory you have available.
The memory is allocated when you init the object, so it's limited to the memory free of your device. Moreover the NSArray size is fixed when you init it.
NSArray is a container of pointers to other objects. Its maximum capacity is defined by NSUInteger (on the latest versions of the available OSs):
When building 32-bit applications, NSUInteger is a 32-bit unsigned integer. A 64-bit application treats NSUInteger as a 64-bit unsigned integer
Therefore, whatever the size of NSUInteger is on a given device is the maximum number of object pointers it can contain. However, as Eimantas alluded to in his answer, this isn't the same as "how many objects can it hold" because this depends on available memory. You may not have enough RAM available at a given moment to allocate an array with six billion slots for example ...
In most cases concerning the upper limits of programming structures and the like:
"If you have to ask, you're probably doing it wrong" - TheDailyWTF.com
Have you tried to find out? ;)
NSMutableArray * a = [[NSMutableArray alloc] init];
NSUInteger i = 0;
@try {
while (1) {
[a addObject:@"hi"];
i++;
}
} @catch (NSException * e) {
NSLog(@"added %llu elements", i);
}