1

This should be rather easy and probably I'm just missing a small thing: I have an array of images called defaultImages

NSMutableArray *defaultLetters;

then I add the letters needed (array length then is 42)

later I'm trying to replace one of the images in the array with another image. Like this:

[defaultLetters replaceObjectAtIndex:0 withObject:croppedPhoto];

but I'm getting an error saying: "-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x180ae190" is there a step I'm missing?

suMi
  • 1,536
  • 1
  • 17
  • 30

2 Answers2

8

I think you assign value like this

defaultLetters = anotherMutableArray;

If you do like this, then please replace as below..

defaultLetters = [anotherMutableArray mutableCopy];

Ater you can replace object in that array

[defaultLetters replaceObjectAtIndex:0 withObject:croppedPhoto];

Try this..Because if you directly assign you can't insert or remove.

TamilKing
  • 1,643
  • 1
  • 12
  • 23
7

You assigned a NSArray object to defaultLetters, not a NSMutableArray.

__NSArrayI is a private Subclass of NSArray. The I stands for immutable.

see What is __NSArrayI and __NSArrayM? How to convert to NSArray?


if you can't tell for sure, if it is an NSArray or an NSMutableArray you are assigning, you can always test.

if(![defaultLetters respondsToSelector:@selector(replaceObjectAtIndex:withObject:)]){
    defaultLetters = [defaultLetters mutableCopy];
}

But this might indicate an architectural issue within your code, as you should know for certain what objects you are dealing with.

Community
  • 1
  • 1
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178