开发者

iOS: replace an object inside an array of array

开发者 https://www.devze.com 2023-03-12 06:42 出处:网络
My code is: [[arrayOne objectAtIndex:indexSelected] replaceObjectAtIndex:1 withObject:new]; NSLog(@\"indexSelected:%d\", indexSelected); // = 0

My code is:

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


NSLog(@"indexSelected:%d", indexSelected); // = 0
NSL开发者_JS百科og(@"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?


This is because NSArray is immutable. Use an NSMutableArray.

0

精彩评论

暂无评论...
验证码 换一张
取 消