如何通过DOT符号访问非构造对象?(Swift Playground)



我对坐标和坐标。当我不实例化实例坐标时,列和行accsss如何?如果是for循环intatientiate坐标,则在Allcoordinate或World时如何实例化。AllPossibleCoordinate不是类型?(世界周围没有督导教义。

let allCoordinates = world.allPossibleCoordinates
var blockSet: [Coordinate] = []
//#-editable-code Tap to enter code
for coordinate in allCoordinates {
    // Check for coordinates with a column > 5 OR a row < 4.
    if coordinate.column > 2 && coordinate.row < 5 {
        // Append coordinate to blockSet.
    }
}

Swift中,for in循环的工作方式与其他语言中的for循环的作用有所不同。for in循环大步在一个范围内(我假设Allcoordinate是可行的(。在提供的示例中,如果变量Allcoordinates是一个可行的范围,则循环将通过该范围内的每个项目,将每个值分配给coordinate每个迭代。有关更多信息,请查看Apple的文档

最新更新