我怎样才能让它发挥作用:
var variable0 : Int = 10
var variable1 : [(name: String, title: String)] = []
variable1.append(name: "name 1", title: "title 1")
variable1.append(name: "name 2", title: "title 2")
var variable2 :NSArray = [variable0,variable1]
我想要一个带有这两个变量的NSArray。 但是得到了一个错误:
Type '[(name:String, title: String)]' does not conform to protocol 'AnyObject
答案 0 :(得分:1)
您无法将其存储在NSArray中,但您可以将其存储为Array<Any>
,因为元组不符合AnyObject
:
var variable0 : Int = 10
var variable1 : [(name: String, title: String)] = []
variable1.append(name: "name 1", title: "title 1")
variable1.append(name: "name 2", title: "title 2")
var variable2 :Array<Any> = [variable0,variable1]
println(variable2[0]) // 10
println(variable2[1]) // [(name 1, title 1), (name 2, title 2)]