我正在学习iOS开发,正在观看YouTube上的一个教程,该教程从2014年开始就非常古老。
import UIKit
protocol GameModelProtocol: class {
func scoreChange(score: Int)
func moveOneTile(from: (Int, Int), to: (Int, Int), value: Int)
func moveTwoTile(from: ((Int, Int), (Int, Int)), to: (Int, Int), value: Int)
func insertTile(location: (Int, Int), value: Int)
}
[![enter image description here][1]][1]
class GameModel: NSObject {
let dim: Int
let limit: Int
var score: Int = 0 {
didSet {
delegate.scoreChange(score: score)
}
}
var gameBoard: SquareGameBoard<TileObject>
let delegate: GameModelProtocol
var queue: [MoveCommand]
var timer: Timer
let maxCommands = 100
let queueDelay = 0.3
init(dim d: Int, limit l: Int, delegate: GameModelProtocol) {
dim = d
limit = l
self.delegate = delegate
queue = [MoveCommand]()
timer = Timer()
gameBoard = SquareGameBoard(dim: d, initialValue: .Empty)
super.init()
}
讲师说他正在将它用作数组。但是我无法弄清楚它的使用方式或如何更改它以使其与Swift 4兼容。
这是YouTube视频的link。
我只是想知道如何替换[MoveCommand]在Swift 4中工作。我已经修复了代码中的大多数问题,但是我无法弄清楚。
答案 0 :(得分:1)
MoveCommand是在AuxiliaryModels.swift中定义的结构。您应该下载完整的项目示例代码:https://github.com/austinzheng/swift-2048
希望这会有所帮助。