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?

1
  • please show us, how you assign something to defaultLetters Commented Oct 25, 2013 at 12:55

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.