objective-c - 获取无错误的数值 "Subscript requires size of interface ' NSArray',这在非稳定 ABI 中不是常量”

标签 objective-c ios cocoa-touch nsarray

如果我有一个 NSArray,并且我想获取其中的每个数字,是否有一种简单的方法可以做到这一点?

我尝试了来自 http://code.flamingleaf.com/category/objective-c/ 那说而不是(其他编程语言中用于数组内下标的方法):

someArray[i]

使用

[someArray objectAtIndex:i];

有什么方法可以获取数值吗?

我不断收到以下类型的错误: “下标需要接口(interface)‘NSArray’的大小,这在非稳定 ABI 中不是常量”

感谢 Kurt Revis 提出的输入真实代码的建议。 我无法重现问题。但这是我最接近的问题:

      for (int i=0; i<4; i++)
            NSLog(@"%i",[[temp objectAtIndex: i]length]);
        for (int i=0; i<4; i++)
            tempNumbers[i]=[[temp objectAtIndex:i] length];
        for (int i=0; i<4; i++)
            NSLog(@"The count at i=%i is %i", i, tempNumbers[i]);

它的作用是:

3   
3   
5   
2   
 the value of i = 0 and tempNumbers[i]=3.000000  
 the value of i = 1 and tempNumbers[i]=3.000000  
 the value of i = 2 and tempNumbers[i]=5.000000  
 the value of i = 3 and tempNumbers[i]=2.000000       

结论:在我可以编写简单的代码来重现问题之前,我不会堵塞这个问题区域。

第二个结论:我将尝试 edc1591 建议的解决方案。

最佳答案

如果不看对象是什么类很难说,但是如果它们是 NSStringNSNumber 类型,您可以使用以下任何方法来获取数值值:

[[someArray objectAtIndex:i] floatValue];
[[someArray objectAtIndex:i] doubleValue];
[[someArray objectAtIndex:i] intValue];
[[someArray objectAtIndex:i] unsignedIntValue];

等...

关于objective-c - 获取无错误的数值 "Subscript requires size of interface ' NSArray',这在非稳定 ABI 中不是常量”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9456374/

相关文章:

objective-c - NSOutlineView SourceList View 上的边距不正确

ios - __NSArrayM 插入对象 :atIndex:]; object cannot be nil

ios - 编译应用程序后,启动时传递的环境变量和参数不起作用

objective-c - 将数组的每个对象与其他每个对象进行比较

iphone - UITableView 单元格文本字段上的 ScrollView

ios - 仅针对 UITableViewCell 的一部分调用 didSelectRowAtIndexPath

ios - 将触摸转发到 UIScrollView

iphone - 可以取消UIPickerView动量动画吗?

ios - 根据firebase逻辑,在uicollectionview中快速分段控制显示/隐藏单元格

ios - didReceiveRemoteNotification :fetchCompletionHandler not being called when app is in background and not connected to Xcode