user4933792
user4933792

Reputation:

Replace object in Array

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'

Upvotes: 0

Views: 748

Answers (2)

user3182143
user3182143

Reputation: 9589

Below code is helpful for you.

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

Upvotes: 2

rob mayoff
rob mayoff

Reputation: 385500

I think this is what you want to do:

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

Upvotes: 1

Related Questions