Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 907
user3673836 Avatar asked Oct 16 '14 18:10

user3673836


1 Answers

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 { }
}
like image 87
CodaFi Avatar answered Oct 06 '22 01:10

CodaFi