cyclingIsBetter
cyclingIsBetter

Reputation: 17591

iOS: replace an object inside an array of array

My code is:

[[arrayOne objectAtIndex:indexSelected] replaceObjectAtIndex:1 withObject:new];


NSLog(@"indexSelected:%d", indexSelected); // = 0
NSLog(@"new:%@", new); // = 26

indexSelected is an int and new is a string

When I try to do this I have an exception that says: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x1cee60'

Why?

Upvotes: 3

Views: 5563

Answers (1)

Joshua Smith
Joshua Smith

Reputation: 6651

This is because NSArray is immutable. Use an NSMutableArray.

Upvotes: 6

Related Questions