0

I have an NSMutableArray with 5 objects

[0] StateGeographicComponent *  0x0a455ba0
[1] StateGeographicComponent *  0x11c374b0
[2] StateGeographicComponent *  0x08e5f720
[3] StateGeographicComponent *  0x11c15430
[4] StateGeographicComponent *  0x0a458f20

After executing the following line of code:

[self.gameComponents removeObjectAtIndex:0];

Instead of simply removing the object at index 0 and sliding everything up an index as I'd expect. The object at index [0] is set to nil AND the object at index [4] is removed.

[0] id  0x00000000
[1] StateGeographicComponent *  0x11c374b0
[2] StateGeographicComponent *  0x08e5f720
[3] StateGeographicComponent *  0x11c15430

Quite perplexing to me..

3
  • 5
    Use NSLog to do the before/after dumps, or use po in the console. The debug display is likely confused. Commented Aug 15, 2013 at 2:49
  • Thanks Hot Licks, I was getting a bit ahead of myself and debugging without actually seeing if the debugger was displaying erroneous data. LVM seems to be quite buggy! Commented Aug 15, 2013 at 4:27
  • Yeah, someone was asking me a couple of days ago why I mostly use po in the console. This is why. Commented Aug 15, 2013 at 11:36

1 Answer 1

-4

Use the following lines of code

[self.gameComponents replaceObjectAtIndex:0 withObject:[NSNull null]];
[self.gameComponents removeLastObject];

The first line of code replaces the object with singleton instance of NSNull and the second line of code removes the last object from the array.

Sign up to request clarification or add additional context in comments.

2 Comments

Neither of which the OP wanted to do.
This seems to be unwanted!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.