我有以下代码,用于从数组中选择一个随机字符串。
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。关于为什么数组的计数返回如此巨大数字的任何想法?谢谢!
答案 0 :(得分:3)
您的问题看起来像是一个调试器工件。例如,它可能与优化相关。有时编译器会生成严重混淆调试器的代码。添加日志语句以确保调试器不只是告诉您谎言。
答案 1 :(得分:0)
答案 2 :(得分:0)
尝试:
NSInteger pmCount = [popupMessages count];