Hi, initWithCapacity:
is declared in NSMutableArray
, but I want to use it to initialize an NSArray
. I there any solution?
views:
544answers:
3
+3
A:
It doesn't make sense to init an NSArray
using initWithCapacity:
, because you can't subsequently add objects. An NSArray
with no objects in has a de facto capacity of 0. What are you really trying to achieve?
Graham Lee
2009-10-01 09:58:25
hai , please will you give the answer to the following urlhttp://stackoverflow.com/questions/1502749/edit-action-in-tableview-without-edit-button
senthil
2009-10-01 10:51:21
That question is completely unrelated to his answer.
Brad Larson
2009-10-01 12:24:45
+3
A:
Since NSArray
objects are immutable (cannot change the objects they contain) there's no use in adjusting the capacity of NSArray
s.
The capacity is the number of objects an array can contain without reallocating memory. It is only used for optimization.
Nikolai Ruhe
2009-10-01 09:58:26
+2
A:
Just make an NSMutableArray
with initWithCapacity:
, fill it with stuff, and then make an NSArray
from it.
You can use either:
NSArray *_immutableArray = [_mutableArray copy];
...
[_immutableArray release];
Or:
NSArray *_immutableArray;
[_immutableArray initWithArray:_mutableArray];
...
[_immutableArray release];
Or:
NSArray *_immutableArray = [NSArray arrayWithArray:_mutableArray];
Alex Reynolds
2009-10-01 10:55:34