我有两个classes
:玩家和敌人都符合protocol
CharacterCharacteristicsProtocol:
class Enemy: CharacterCharacteristicsProtocol {...
class Player: CharacterCharacteristicsProtocol {...
他们既是references
又不values
像是structs
;仍然当我objects
像这样发送 as 参数时:
viewModel.combatButtonIsClicked(attacker: self.player, defender: self.enemy) { result in...
我得到错误
将“CharacterCharacteristicsProtocol”类型的值传递给 inout 参数需要显式“&”
为什么会出现这个?这不应该只发生在structs
吗?
如果我按照编译器的意愿进行操作,inout
并且&
在适当的位置进行操作,那么除了在现在出现错误的闭包中之外
转义闭包捕获“inout”参数“characterVM”
这是它发生的地方(只是为了完成):
func enemyTurn(enemyVM: CharacterCharacteristicsProtocol, characterVM: inout CharacterCharacteristicsProtocol, completion: @escaping(_ enemyReponse: String) -> Void){
let xEnemy = enemyVM.getX()
let yEnemy = enemyVM.getY()
viewModel.enemyShouldMove = true
viewModel.proximityCheck(checkProxyForWho: .enemy, i: xEnemy, j: yEnemy, completion: {
let combat = Combat()
combat.combat(attacker: enemyVM, defender: &characterVM, completion: { result in...
我搜索了如何解决此错误并获得以下建议:“将结构更改为类”...