What is the largest amount of objects I can put in my NSArray?
arrays can't contain nil. There is a special object, NSNull ( [NSNull null] ), that serves as a placeholder for nil.
In Objective-C, arrays take the form of the NSArray class. An NSArray represents an ordered collection of objects. This distinction of being an ordered collection is what makes NSArray the go-to class that it is.
An object representing a static ordered collection, for use instead of an Array constant in cases that require reference semantics.
The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects. This class adds insertion and deletion operations to the basic array-handling behavior inherited from NSArray . NSMutableArray is “toll-free bridged” with its Core Foundation counterpart, CFMutableArray .
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);
}
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.
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
Probably more than your RAM can handle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With