-6

I have an NSMutableArray and I am trying to use the insertObjectAtIndex method, but it does not work. It seems to think I am trying to do something mutable with an immutable array..... but I am using an NS ..... MUTABLE.... Array. So what an earth could be wrong??

Here is my code:

        if ([dataArray count] == 0) {

            // Initialise the audio arrays.
            dataArray = [[NSMutableArray alloc] init];

            // Now add the data to the array.
            [dataArray addObject:@"test 1"];
        }

        else {
            [dataArray insertObject:@"test 2" atIndex:0];
        }

        NSLog(@"d in: %@", dataArray);

The dataArray is defined in the header file like so:

NSMutableArray *dataArray;

Thanks for your time, Dan.

Supertecnoboff
  • 6,406
  • 11
  • 57
  • 98

1 Answers1

0

Oh sorry everyone, I just figured out what was wrong. I did edit the code in my question a bit, but basically what I am actually populating the NSMutableArray with is an array stored in an NSUserDefault, (which of course returns immutable arrays only).

So even though I am using an NSMutableArray to store the data, its still has immutable contents. In order to over come this, I ended up using "mutableCopy" iOS method to get a mutable copy of the contents of the NSUserDefaults array.

Supertecnoboff
  • 6,406
  • 11
  • 57
  • 98