replaceObjectAtIndex给出了一个错误,无法弄清楚为什么?

And*_*rew 0 iphone objective-c nsmutablearray

所以这是我的代码:

[dataCenter.tempPalette replaceObjectAtIndex:9 withObject:selectedColour];
Run Code Online (Sandbox Code Playgroud)

对象9确实存在,它当前是一个int(不确定是否重要).selectedColour也是一个int.dataCenter.tempPalette是一个NSMutableArray.

它给我的错误是这样的:

传递'replaceObjectsAtIndex:withObject:'的参数2使得指针来自整数而没有强制转换.

有任何想法吗?

Cal*_*leb 6

整数不是对象.如果要在NSMutableArray中存储整数,则需要首先使用+ [NSNumber numberWithInt:]将它们转换为NSNumbers.错误消息抱怨您正在传递一个需要指针(对象)的int.