使用“NSArray *”类型的表达式初始化“NSMutableArray *”时不兼容的指针类型

Spo*_*ude -5 objective-c nsmutablearray nsarray

这是我的代码导致上述警告:

    NSMutableArray *tbValueArray = [NSArray arrayWithObjects:oServices1.text,
                oServices2.text,oServices3.text,oServices4.text,oServices5.text,oServices6.text,
                oServices7.text,oServices8.text,oServices9.text,oServices10.text,oServices11.text,
                oServices12.text,oServices13.text,oServices14.text,oServices15.text,oServices16.text,
                oServices17.text,oServices18.text,oServices19.text,oServices20.text,oServices21.text,
                oServices22.text,oServices23.text,oServices24.text,nil];
Run Code Online (Sandbox Code Playgroud)

如何更改此设置以删除警告?(我查看了 Google 和 SO,没有发现任何适用的内容)。

Chu*_*uck 5

你想创建一个 NSMutableArray 还是 NSArray ?您已将变量声明为 类型NSMutableArray*,但右侧的表达式创建了一个 NSArray。如果你希望这个数组是可变的,请将 的接收者更改arrayWithObjects:为 NSMutableArray;如果不是,请更改声明以正确地将其识别为 NSArray 而不是 NSMutableArray。

  • @spokane-dude - 伙计,抱怨被否决肯定会被否决。 (4认同)
  • @spokane-dude:请停止指责人们对你投反对票。*特别是*那些给你正确答案的人。(而且投票也是匿名的。) (2认同)