我有一个元组数组定义为:
var points2D:Array=[(1,1),(2,3),(4,3),(9,5),(3,3),(7,6),(5,6)]
我试着这样做:
func foo(){
for (x,y) in points2D{
}
}
我收到此错误消息:
'τ_0_0' is not convertible to '(@lvalue Array, @lvalue Array)'
这是什么意思?我做错了什么?
答案 0 :(得分:2)
points2D的类型不是Array
,而是Array<(Int,Int)>
所以让Swift推断出类型:
var points2D = [(1,1),(2,3),(4,3),(9,5),(3,3),(7,6),(5,6)]
或明确设置正确的类型:
var points2D:Array<(Int,Int)> = [(1,1),(2,3),(4,3),(9,5),(3,3),(7,6),(5,6)]