I have this mutable array:
myIntegers = [NSMutableArray array];
[myIntegers addObject:[NSNumber numberWithInteger:indexDelete - 1]];
NSLog (@"Array: %@", myIntegers);
If I execute the code twice, with indexDelete first being 1 and then 2, I get this result:
Array: (
1
)
and then:
Array: (
2
)
But I would like to store both numbers like this:
Array: (
1
2
)
Why is it not adding, but replacing the object??
You’re creating a new empty array every time that code executes, on this line:
Adding an object to an empty array always leads to there being one object in that array.