我正在阅读一个用 Swift 编写的 2048 项目,我使用的是 Xcode beta 3。
这是 Swift 中的一个闭包,其中 direction
是 MoveDirection
let coordinateGenerator: (Int) -> [(Int, Int)] = { (iteration: Int) -> [(Int, Int)] in
let buffer = Array<(Int, Int)>(count:self.dimension, repeatedValue: (0, 0))
for i in 0..<self.dimension {
switch direction {
case .Up: buffer[i] = (i, iteration)
case .Down: buffer[i] = (self.dimension - i - 1, iteration)
case .Left: buffer[i] = (iteration, i)
case .Right: buffer[i] = (iteration, self.dimension - i - 1)
}
}
return buffer
}
MoveDirection
枚举如下:
enum MoveDirection {
case Up
case Down
case Left
case Right
}
Xcode beta 3 出现以下错误:
这只是 beta 3 的问题吗?
最佳答案
我的猜测是,这只是非常的错误报告,实际的错误是您正在改变一个不可变的数组。尝试将其更改为:
var buffer = [(Int, Int)](...
而不是使用let。
关于ios - 为什么编译器在使用 Swift 的 Xcode 6 beta 3 中提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24748028/