In a book, I see the code:
words = [[NSMutableArray alloc] initWithCapacity:[masterWordList count]];
and let's say [masterWordList count]
is 15. And then the code built the array up by using a loop for 10 times:
[words addObject:[masterWordList objectAtIndex:randomNum]];
I wonder why words
has to be initWithCapacity
... and to 15 slots? Can't it be 10 or 11 (if a nil is needed at the end... and also, won't addObject
automatically grow the array size? I tried using init
instead of initWithCapacity
and the code worked too. So can the code in the book be simplified to just init
?