表达式类型 'NSMutableArray!'在没有更多上下文的情况下是模棱两可的 [英] Expression type 'NSMutableArray!' is ambiguous without more context

查看:33
本文介绍了表达式类型 'NSMutableArray!'在没有更多上下文的情况下是模棱两可的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

定义的变量 Leftover

The varible Leftover defined

var leftOvers : NSMutableArray!

定义 for 循环时出错

i get an error when i define a for loop

 for leftOver: NSValue! in self.leftOvers {
}

我得到的错误是.表达式类型 'NSMutableArray!'没有更多上下文是模棱两可的

The error i get is. Expression type 'NSMutableArray!' is ambiguous without more context

推荐答案

编译器不知道 NSMutableArray 的内容类型和可变集合类型 NSMutableArray并且 NSMutableDictionary 不能隐式桥接到 Swift.

The compiler doesn't know the type of the contents of NSMutableArray and the mutable collection types NSMutableArray and NSMutableDictionary cannot be implicitly bridged to Swift.

由于数组的内容似乎是 NSValue 对象,因此考虑将 leftOvers 声明为原生 Swift 类型.使用 var 关键字,您可以免费获得可变性.

Since the contents of the array seem to be NSValue objects consider to declare leftOvers as a native Swift type. Using the var keyword you get mutability for free.

var leftOvers : [NSValue]!

在许多情况下——特别是对于像数据源数组这样的具体对象——数组应该被声明为非可选

In many cases – in particular for concrete objects like data source arrays – the array is supposed to be declared as non-optional

var leftOvers = [NSValue]()

这篇关于表达式类型 'NSMutableArray!'在没有更多上下文的情况下是模棱两可的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆