xcode iOS:替换数组数组中的对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6296398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS: replace an object inside an array of array
提问by cyclingIsBetter
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
indexSelected
是一个 int 并且new
是一个字符串
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'
当我尝试这样做时,我有一个例外: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x1cee60'
Why?
为什么?
回答by Joshua Smith
This is because NSArray is immutable. Use an NSMutableArray.
这是因为 NSArray 是不可变的。使用 NSMutableArray。