0
votes

So I'm trying to change all the booleans in an NSMutableArray that I made which I followed from here.

i have:

@property (nonatomic, retain) NSMutableArray *isDinosaurTapped;

and synthesized:

@synthesize isDinosaurTapped;

and set up [EDITED to show isDinosaurTapped]:

NSMutableArray *newDinosaurTaps = [[NSMutableArray alloc] init];
    for( int i = 0; i < [dinoSprites count]; i++ )
    {
        NSNumber *isTapped = [posPlist valueForKeyPath:[NSString stringWithFormat:@"Dinosaurs.Dinosaur_%i.isTapped", i]];
        [newDinosaurTaps addObject:isTapped];
    }
    self.isDinosaurTapped = [newDinosaurTaps copy];


    for( int i = 0; i < [isDinosaurTapped count]; i++ )
    {
        [isDinosaurTapped replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:NO]];
    }

When I build its fine, however when I actually build and run, I keep getting a SIGABRT: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance.

Have I set the properties of the NSMutableArray incorrectly? But according to this, my properties should be ok.

Any feedback is greatly appreciated! :D

2
show some lines of code where you set isDinosaurTapped. ie self.isDinosaurTapped = ... or isDinosaurTapped = ... I think it is being set to an instance of NSArray - Jesse Black
Why doesn't the compiler complain about you setting this to NSArray? It should show a yellow warning somewhere about incompatible types. - CodaFi

2 Answers

5
votes

You are trying to mutate an immutable array. Is it declared as NSMutableArray, or NSArray, and if it is mutable, did you call -copy, or -mutableCopy?

In core foundation, NSMutableArrays are internally known as __NSArrayM (for mutable), and NSArrays are known as __NSArrayI (for immutable).

0
votes

It complains that you are sending the replaceObjectAtIndex:withObject: selector to an NSArray which is immutable/unmodifiable after creation. NSMutableArray is the mutable version of NSArray. Did you initialize the isDinosaurTapped property with an NSArray? You should be calling something like this before you use your property.

self.isDinosaurTapped = [NSMutableArray array]; // or another nsmutable creation method.

If you have an NSArray that you want to clone into your property you can use:

self.isDinosaurTapped = [NSMutableArray arrayWithArray:array];