0

I try to replace a object in a NSMutableArray. To figure out, what the index number is, I use following code:

 NSUInteger index = [self.nameArray indexOfObject:[NSString stringWithFormat:@"James"]];

Now I try to replace it:

self.nameArray = [[NSMutableArray alloc] replaceObjectAtIndex:index withObject:@"Johanna"];

But even I want to start the app, I will become an error: Assigning to 'NSMutableArray *' from incompatible type 'void'

2 Answers 2

2

Below code is helpful for you.

[self.nameArray replaceObjectAtIndex:index withObject:@"Johanna"];
Sign up to request clarification or add additional context in comments.

Comments

1

I think this is what you want to do:

[self.nameArray replaceObjectAtIndex:index withObject:@"Johanna"];

1 Comment

The answer is correct but you don't explain why his approach was wrong. I thing it would be more educational if you explained what he was doing incorrectly.

Your Answer

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