开发者

replaceObjectAtIndex is giving an error, can't figure out why?

So this is the code I have:

[dataCenter.tempPalette replaceObjectAtIndex:9 withObject:selectedColour];

Object 9 does exist, and it's currently an int开发者_运维技巧 (not sure if that matters). selectedColour is also an int. dataCenter.tempPalette is a NSMutableArray.

The error it gives me is this:

Passing argument 2 of 'replaceObjectsAtIndex:withObject:' makes pointer from integer without a cast.

Any ideas?


ints aren't objects. If you want to store integers in an NSMutableArray, you'll need to turn them into NSNumbers first using +[NSNumber numberWithInt:]. The error message is complaining that you're passing an int where a pointer (to an object) is required.


The second param of replaceObjectAtIndex needs to be a valid pointer to an object. From your description, it sounds like you are trying to pass in an int value ( selectedColour ), which is not a valid reference to an object.

I believe, instead of passing in the selectedColour int value, you want to pass a reference to the actual color object. This would probably be a reference to a UIColor object.

Also keep in mind, if you are trying to store many objects representing the same color. For purposes of using memory efficiently, you will probably want to store in your tempPallette array references pointing to the same color object for those entries that use the same color.

Hope this helps. Good Luck.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜