我有两个多维NSMutableArray。每个主NSMutableArray中都有四个NSMutableArray。我想将第一个数组中一个位置的数据与第二个数组中的数据交换,并且我在为replaceObjectatIndex: withObject:的语法苦苦挣扎。这是我的代码行:

[newStock replaceObjectAtIndex:0 objectAtIndex:0 withObject: [[oldStock objectAtIndex: 0] objectAtIndex: 0]];

我试图将数据从oldStock数组放入newStock数组,并且收到错误消息:“'NSMutableArray'的不可见@interface声明了选择器'replaceObjectAtIndex:'”。我已经使用非多维数组完成了此操作,因此我相信选择器是有效的。

最佳答案

Objective-C中的旧语法如下所示:

[[newStock objectAtIndex:0] replaceObjectAtIndex:0 withObject: [[oldStock objectAtIndex: 0] objectAtIndex: 0]];

幸运的是,您现在可以使用新语法:
newStock[0][0] = oldStock[0][0];

关于objective-c - NSMutableArray没有可见的接口(interface)声明选择器replaceObjectAtIndex :,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34457530/

10-12 00:11
查看更多