Creating an Empty NSArray

in C, I can simply declare an array as follows:

int array[500]; 

declare an array of size 500, which can then be filled later. Is it possible to do this in NSArray? I understand that for NSMutableArray there is an arrayWithCapacity class method for "creating" and an empty array (or at least declare an 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 populate the contents later in the for loop.

thank

+5
source share
1 answer

, int array[500]; - , . NSArray , NSMutableArray, , .

, , :

NSMutableArray *array = [NSMutableArray arrayWithCapacity:500];
for (int i = 0 ; i != 500 ; i++) {
     [array addObject:@(i)];
}

NSMutableArray NSArray, NSMutableArray*, NSArray* .

+1

All Articles