Reputation: 923
Once an Array is initialized, in order to set value of desired position, I am using
[self.appName replaceObjectAtIndex:x withObject:[self.appCell objectAtIndex: 0]];
Problem is that if I initialize appName array without objects, this array keeps empty and I must initialize it using initWithObjects and then works. Problem is that I do not know the size of an array and if I set it like:
NSMutableArray *nameArray = [[ NSMutableArray alloc] initWithObjects:@"test",@"test",@"test",@"test", nil];
self.appName = nameArray;
[nameArray release];
For example, works from 0 to 3 but from position 4 to following ones, after replaceObjectAtIndex, position has a nil value. How to solve it? Thank you
Upvotes: 0
Views: 963
Reputation: 119292
It's a mutable array, you can add objects (to the end) and insert objects (in the middle) as well, whenever you like:
NSMutableArray *nameArray = [[NSMutableArray alloc] init];
[nameArray addObject:@"test"];
[nameArray insertObject:@"another test" atIndex:0];
[nameArray removeObjectAtIndex:1];
You can do this anywhere you have a pointer to the mutable array.
Upvotes: 1