Reputation: 125
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
Upvotes: 0
Views: 528
Reputation: 43330
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).
Upvotes: 5
Reputation: 7287
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];
Upvotes: 0