in C I can simply declare an array like this:
int array[500];
to declare an array of size 500 which can then be filled later. Is it possibel to do the same thing in NSArray? I understand for the NSMutableArray there is the arrayWithCapacity class method to “create” and empty array (or at least declare the array to be filled later). Is there a way to do something similar for NSArray, since I know the exact size of my array I want to fill in the contents later in a “for” loop.
Thanks
Technically,
int array[500];does not create an empty array – it creates an array full of zeros. SinceNSArrays is immutable, you do need to useNSMutableArrayif you’d like to be able to populate it later.You can make an array with a specific capacity, and then put objects into it, like this:
Since
NSMutableArrayis anNSArray, you can create it in a method asNSMutableArray*, and then return it asNSArray*to the callers.