0

For some reason, I keep getting this error when I run my app:

[__NSArrayI removeAllObjects]: unrecognized selector sent to instance

I set up the NSMutableArray in .m like this:

@implementation ChooseViewController
{
    NSMutableArray *trackName;
}

And populate it like this:

trackName = [JSON valueForKeyPath:@"results.trackName"];

But when I run this code, it gives me the error:

[trackName removeAllObjects];

Everything else works fine and the data in trackName works. It's just messing up when I run this code. The only other time trackName array is mentioned is for table view count:

return [trackName count];

Do you see anything wrong? I believe the problem is that somewhere it thinks it's an NSArray, but none of them are.

1
  • valueforkeypath is returning non mutable array so before assigning to trackName convert into mutable using mutableCopy function. May 1, 2015 at 0:43

1 Answer 1

9

Mutable problem.

trackName = [JSON valueForKeyPath:@"results.trackName"];

This line will result into immutable array to trackName. Change to this:

trackName = [[JSON valueForKeyPath:@"results.trackName"] mutableCopy];

Now, trackName is mutable so that you can call.

[trackName removeAllObjects];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.