首页 > 解决方案 > 什么可以替代 Swift 4 中的 [MoveCommand]

问题描述

我正在学习 iOS 开发,并且正在观看 2014 年以来非常古老的 YouTube 教程。

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 视频的链接。

我只是想知道如何替换 [MoveCommand] 以在 Swift 4 中工作。我已经修复了代码中的大部分问题,但这个我无法弄清楚。

在此处输入图像描述

标签: iosswift4

解决方案


MoveCommand 是一个在 AuxiliaryModels.swift 中定义的结构。您应该下载完整的项目示例代码:https
://github.com/austingzheng/swift-2048 希望这会有所帮助。


推荐阅读