【问题标题】:Cannot convert value of type string to expected argument type Int无法将字符串类型的值转换为预期的参数类型 Int
【发布时间】:2017-09-11 23:35:42
【问题描述】:

我在玩代码。我在 GitHub (https://github.com/avijeets/ConnectFour) 上找到了一个我无法清除的错误。

错误是:

“无法将 '[[CFCellState]]' 类型的值转换为预期参数 输入'Int'"

定义CFCellState的VC顶部的代码:

enum CFCellState: CustomStringConvertible {
    case empty
    case occupied(CFPlayer)

    var description: String {
        switch self {
        case .empty:
            return "empty"
        case .occupied(let player):
            return player.description
        }
    }
}

发生错误的代码:

self.init(player: current!, opponent: opponent!, columns:ConnectFour.boardFrom(json: queryItems[1].value!)!)

【问题讨论】:

    标签: json swift


    【解决方案1】:

    试试这个:

    self.init(player: current!, opponent: opponent!, board: ConnectFour.boardFrom(json: queryItems[1].value!)!)
    

    为了使其工作,您可能需要从ConnectFour.swift 文件的这一行中删除 private 关键字(查看第 98 行):

    private init(player: CFPlayer, opponent: CFPlayer, board: [[CFCellState]]) { ....
    

    【讨论】:

    • 当我更改为棋盘时,xcode 指出调用中的参数标签不正确(有 'player:opponent:board:',预期为 'player:opponent:columns:')并提供更改为列的选项。
    • 做到了,非常感谢。现在它在玩家 2 在同一行代码上的移动中崩溃并出现致命错误:在展开 Optional 值时意外发现 nil。好玩好玩。
    猜你喜欢
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多