ios - 为什么编译器在使用 Swift 的 Xcode 6 beta 3 中提示?

标签 ios xcode swift

我正在阅读一个用 Swift 编写的 2048 项目,我使用的是 Xcode beta 3。

这是 Swift 中的一个闭包,其中 directionMoveDirection

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 出现以下错误:

enter image description here

这只是 beta 3 的问题吗?

最佳答案

我的猜测是,这只是非常的错误报告,实际的错误是您正在改变一个不可变的数组。尝试将其更改为:

var buffer = [(Int, Int)](...

而不是使用let。

关于ios - 为什么编译器在使用 Swift 的 Xcode 6 beta 3 中提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24748028/

相关文章:

objective-c - 从 NSString 解析 NSDate 时出错

ios - 当我返回菜单时,应用程序崩溃(线程 1 : signal SIGABRT)

ios - 电话号码的 Swift 2 国家代码

ios - UIStoryboardSegue : view is not displayed during animation

ios - 全局化 UIAlertView

android - 按下设备后退按钮时出现 Flutter WebView 异常

ios - dyld : Library not loaded: @rpath/libswiftCore. 适用于所有 Swift 应用程序的 dylib

ios - WKWebView 打不开 https ://itunes. apple.com/app/id123456 链接

ios - 如何在没有委托(delegate)的情况下处理 UITextField 值更改?

swift - Swift 3 中数据的 MD5