Swift:SKAction.runBlock - >在调用中缺少参数'completion'的参数但是为什么?

时间:2021-07-28 09:40:42

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

我是斯威夫特的noobie。我无法弄清楚为什么这段代码:

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 个解决方案

#1


10  

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

类型检查器中的另一个奇怪的错误。因为self.addLabel(self.statements)的类型不是Void - > Void它是Void,编译器假设你在其他地方调用另一个方法(其他地方的地方,我没有线索。没有名为runBlock的方法(_ :)我能找到的任何地方)。当这样的事情发生时尝试一个明确的闭包

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 { }
}

#1


10  

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

类型检查器中的另一个奇怪的错误。因为self.addLabel(self.statements)的类型不是Void - > Void它是Void,编译器假设你在其他地方调用另一个方法(其他地方的地方,我没有线索。没有名为runBlock的方法(_ :)我能找到的任何地方)。当这样的事情发生时尝试一个明确的闭包

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 { }
}