我正在玩代码。我在 GitHub ( https://github.com/avijeets/ConnectFour ) 上找到了这个问题,并被一个无法清除的错误彻底难住了。
错误是:
"Cannot convert value of type '[[CFCellState]]' to expected argument type 'Int'"
来自 VC 顶部的代码,其中定义了 CFCellState
:
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!)!)
最佳答案
试试这个:
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]]) { ....
关于json - 无法将字符串类型的值转换为预期的参数类型 Int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43433046/