Swift: SKAction.runBlock -> Missing argument for parameter 'completion' in call BUT WHY?

六月ゝ 毕业季﹏ 提交于 2019-12-06 03:41:38

问题


I'm noobie in Swift. I can't figure out why this code:

class GameScene: SKScene, SKPhysicsContactDelegate {
  var statements = Statements()

 override func didMoveToView(view: SKView) {
    runAction(SKAction.repeatActionForever(
       SKAction.sequence([
         SKAction.runBlock(addLabel(statements)),
         SKAction.waitForDuration(2.0)
       ])
     ))
 }
 func addLabel(statements: Statements) {...}
}

Results to: Missing argument for parameter 'completion' in call


回答1:


Yet another weird bug in the type checker. Because the type of self.addLabel(self.statements) is not Void -> Void it's Void, the compiler assumed you were invoking another method somewhere else (where that somewhere else is, I have no clue. There's no method named runBlock(_:) anywhere I can find). Try an explicit closure when stuff like this happens

class GameScene: SKScene {
    var statements = Statements()

    override func didMoveToView(view: SKView) {
        runAction(SKAction.repeatActionForever(SKAction.sequence([
            SKAction.runBlock({ self.addLabel(self.statements) }),
            SKAction.waitForDuration(2.0)
        ])))
    }

    func addLabel(statements: Statements) -> Void { }
}


来源:https://stackoverflow.com/questions/26411883/swift-skaction-runblock-missing-argument-for-parameter-completion-in-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!