objective-c - Objective-C获取数组元素?

标签 objective-c ios arrays

这行代码给出了ans。 2(正确)

int def = arc4random() % 2;
NSLog(@"%@",[uniqueNumbers objectAtIndex:def]);

但是当我使用
int def = arc4random() % 2;
//NSLog(@"%@",[uniqueNumbers objectAtIndex:def]);
c1 = (int)[uniqueNumbers objectAtIndex:def];
NSLog(@"%d", c1);

得出115669616。其中c1是整数。问题是什么?

最佳答案

尝试c1 = [[uniqueNumbers objectAtIndex:def] intValue];

关于objective-c - Objective-C获取数组元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12054495/

相关文章:

objective-c - 寻找特定的 Cocoa 日志框架

objective-c - 单击单元格内容 View 的按钮后如何访问单元格信息?

ios - 为什么线性渐变没有完全应用到ios按钮上

arrays - 将 3 维数组转换为数据框

ios - 如何更改放置在原型(prototype)单元格中的 UIButton 标题?

iphone - 如何动态添加一个 UIView

ios - 如何使单元格适应 TextView ?

ios - 无法在 Xcode 6.1/段错误 : 11 中存档工作 6.0.1 Swift 项目

javascript - if 数组元素在 for 循环内有条件

c - Sscanf 用于命令行获取的字符串