0

我有以下代码,旨在从数组中选择一个随机字符串。

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。关于为什么数组的计数返回如此巨大的数字的任何想法?谢谢!

4

3 回答 3

3

您的问题看起来像是一个调试器工件。例如,它可能与优化相关。有时编译器生成的代码会严重混淆调试器。添加一条日志语句以确保调试器不只是在说谎。

于 2013-07-19T23:57:07.327 回答
0

" count" 不是属性,AFAIK

我通常获取数组计数的方式是:

[popupMessages count];
于 2013-07-19T23:40:41.820 回答
0

尝试:

NSInteger pmCount = [popupMessages count];
于 2013-07-19T23:41:09.840 回答