我在操场上浓缩了我的问题场景:
@objc protocol Prot {}
class Cla : Prot {}
var myArray: [ (aString: String, prot: [Prot] ) ] = []
var myProts: [Prot]? = [Cla()]
// error: type 'T' does not conform to protocol 'IntegerLiteralConvertible'
myArray.append(aString: "myname", prot: myProts!)
// works
myArray.append(aString: "myname", prot: myProts! as [Prot])
// works
if let myProts: [Prot] = myProts {
myArray.append(aString: "myname", prot: myProts)
}
为什么这里不接受强制解包?
Xcode 6.1.1
答案 0 :(得分:0)
只是编译器感到困惑 - 试试这个:
let tuple = (aString: "myname", prot: myProts!)
myArray.append(tuple)
由于某种原因,在某些情况下,它无法在传递给函数/方法时检测到元组。并且,正如经常发生的那样,错误消息没有多大帮助。