gpt4 book ai didi

ios - swift 1.2 "Cannot express tuple conversion"错误

转载 作者:可可西里 更新时间:2023-11-01 00:16:50 26 4
gpt4 key购买 nike

这个方法在 Swift 的最后一个稳定版本中运行良好,但在 Swift 1.2 中无法编译:

  final func rotateBlocks(orientation: Orientation) {
if let blockRowColumnTranslation:Array<(columnDiff: Int, rowDiff: Int)> = blockRowColumnPositions[orientation] {
for (idx, (columnDiff:Int, rowDiff:Int)) in enumerate(blockRowColumnTranslation) {
blocks[idx].column = column + columnDiff
blocks[idx].row = row + rowDiff
}
}
}

这一行:

for (idx, (columnDiff:Int, rowDiff:Int)) in enumerate(blockRowColumnTranslation) {

抛出以下错误:

"Cannot express tuple conversion "(index:Int, element:(columnDiff:Int,rowDiff:Int)) to "(Int, (Int, Int))"

关于这里发生的事情以及如何解决它有什么想法吗?

最佳答案

我会使用 typealias 来简化,但下面的编译对我来说没有错误。

var row: Int = 0
var column: Int = 1
struct block {
var column: Int
var row: Int
}
var blocks = [block]()

enum Orientation { case Up; case Down; }
typealias Diff = (columnDiff: Int, rowDiff: Int)
typealias DiffArray = Array<Diff>
typealias DiffArrayDict = [Orientation: DiffArray]

var blockRowColumnPositions = DiffArrayDict();

func rotateBlocks(orientation: Orientation) {
if let blockRowColumnTranslation: DiffArray = blockRowColumnPositions[orientation] {
for (idx, diff) in enumerate(blockRowColumnTranslation) {
blocks[idx].column = column + diff.columnDiff
blocks[idx].row = row + diff.rowDiff
}
}
}

关于ios - swift 1.2 "Cannot express tuple conversion"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28866426/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com