I’m trying to addobjects to a nsmutable array in lion, xcode 4.3 using ARC. the following is causing the program to crash with SIGABRT
NSMutableArray *myArray = [NSMutableArray arrayWithCapacity:10];
[myArray insertObject:@"Hello World" AtIndex:5]
how can i add custom objects to any index in the array?
Thanks in advance for your help.
If you want to use
NSArrayin the same manner of C fixed-size array, I suggest you fill theNSArrayinstance with as many[NSNull null]as you want for array size, e.g. 10 items in this case.And when you want to insert object, use
replaceObjectAtIndex:withObject:instead. The size of the array won’t change.You also need to check against [NSNull null] when accessing item.