You cannot access the property capacity, and it does not represent a filled size (as kennytm has eloquently described).
One approach may be to get the class from NSMutableArrayand hook the method initWithCapacity, write initialCapacityand then collapse it in the property. But if you're in a hurry, you can use this simple method below:
Create a function:
NSMutableArray* createArrayWithSize(NSUInteger number)
{
NSMutableArray* array = [[NSMutableArray alloc] initWithCapacity:number];
for( NSUInteger i=0;i<number; i++ )
{
array[i]=[NSNull null];
}
return array;
}
Then initialize your NSMutableArray as follows.
myMagicArray = createArrayWithSize(10);
[myMagicArray count] now it will be 10.
source
share