我有以下代码,旨在从数组中选择一个随机字符串。NSArray.count返回不正确的巨大整数
NSArray *popupMessages = [NSArray arrayWithObjects:
@"Shoulda' been bobbin' and weaving! Need anything from the shop?",
@"Don't forget you can use old boss's guns! Available in the shop!",
@"Hey Chaz, you Bojo! You need more POWER! Come by the shop for some better weapons!",
@"Aw… lame. Maybe I got something that can help you out here at my shop!",
nil];
int pmCount = popupMessages.count; // Breakpoint Here - pmCount = 971056545
int messageIndex = arc4random() % pmCount; // Breakpoint Here - same as above
我使用ARC和cocos2d。关于为什么数组返回如此庞大的数字的任何想法?谢谢!
嗯,考虑到我只是逐字复制了你的代码,它对我来说显示得很好。 – Stakenborg
真的吗?谢谢你这样做 - 确认它可能与xcode等有关,也许是一个可变的冲突。 –
这是我第一次想到,也许你有popupMessages声明为一个属性,它被合成为_popupMessages,但你使用popupMessages没有自我?或者其他的东西?也许?第一步是重命名数组,看看会发生什么。 – Stakenborg