类型序列不符合协议序列(Swift Beta 4)

类型序列不符合协议序列(Swift Beta 4),swift,Swift,以下代码以前在Swift Beta 2中运行良好,现在不再在Beta 4中编译。谁能解释一下原因吗 for dx in [-1, 0, 1] { // Fine for dy in (dx == 0) ? [-1, 1] : [0, (xIndex % 2) == 0 ? -1 : 1] { // Now fails // ... } } 给出的错误是“类型‘序列’不符合协议‘序列’”。我知道如何修复它(只是显式地设置内部范围,而不是使用?运算符),但为什么现在这

以下代码以前在Swift Beta 2中运行良好,现在不再在Beta 4中编译。谁能解释一下原因吗

for dx in [-1, 0, 1] { // Fine
    for dy in (dx == 0) ? [-1, 1] : [0, (xIndex % 2) == 0 ? -1 : 1] { // Now fails
       // ...
    }
}
给出的错误是“类型‘序列’不符合协议‘序列’”。我知道如何修复它(只是显式地设置内部范围,而不是使用?运算符),但为什么现在这是一个非法表达式

全部功能是:

func tilesAdjacentTo(#xIndex: Int, yIndex: Int) -> [HexTile] {
    var adjacent = [HexTile]()
    // We want to do this, where dy is -1 for even columns and +1 for odd
    // adjacent += self.pieces[xIndex + 0][yIndex + 1]
    // adjacent += self.pieces[xIndex + 0][yIndex - 1]
    // adjacent += self.pieces[xIndex + 1][yIndex + 0]
    // adjacent += self.pieces[xIndex + 1][yIndex + dy]
    // adjacent += self.pieces[xIndex - 1][yIndex + 0]
    // adjacent += self.pieces[xIndex - 1][yIndex + dy]
    for dx in [-1, 0, 1] {
        for dy in (dx == 0) ? [-1, 1] : [0, (xIndex % 2) == 0 ? -1 : 1] {
            let x = xIndex + dx
            let y = yIndex + dy
            if (x > 0) &&
                (x <= self.maxX) &&
                (y > 0) &&
                (y <= self.maxY)
            {
                adjacent += self.pieces[x][y]
            }
        }
    }
    //println("Adjacent \(adjacent.count)")
    return adjacent
}
func tilesajacentto(#xIndex:Int,yIndex:Int)->[HexTile]{
相邻变量=[HexTile]()
//我们想这样做,其中dy对于偶数列是-1,对于奇数列是+1
//相邻+=自身碎片[xIndex+0][yIndex+1]
//相邻+=自身碎片[xIndex+0][yIndex-1]
//相邻+=自身碎片[xIndex+1][yIndex+0]
//相邻+=自身碎片[xIndex+1][yIndex+dy]
//相邻+=自身碎片[xIndex-1][yIndex+0]
//相邻+=自身碎片[xIndex-1][yIndex+dy]
对于[-1,0,1]中的dx{
对于dyin(dx==0)?[-1,1]:[0,(xIndex%2)==0?-1:1]{
设x=xIndex+dx
设y=yIndex+dy
如果(x>0)&&
(x 0)&&

(y)您的代码示例中缺少变量xIndex的声明吗?不,@AnthonyKong-我已经用更多的上下文更新了这个问题。谢谢。由于缺少HexTile类声明,代码没有真正编译。无论如何,您的代码也在beta 3中工作。但是考虑到swift还很年轻,我们不应该对任何问题感到惊讶语法改变。贝斯迪,如果你把代码分解成多行代码,代码会更干净。很抱歉-因此要求提供最少的代码示例。请返回初始片段,让xIndex为Int。如果你愿意,我也可以向你发送包含HexTile定义的整个源代码,但它实际上没有详细说明问题。问题是我的前一篇文章的第二行为什么没有编译呢?正如我在前一篇文章中提到的,斯威夫特是一种非常年轻的语言,而且还在不断发展。现在,语言的创造者可能认为这个语法是非法的。但是如果你不同意,你真的应该把它作为一个bug报告给苹果。毕竟XCODE 6 Beta 4看起来很笨拙。(这就是我坚持beta 3的原因)