无法将'()'类型的值转换为预期的参数'() - > void'

时间:2022-05-17 16:34:59

I have viewed questions with this same error but can't seem to relate it to my issue. I am running a thread as such:

我已经用同样的错误查看了问题,但似乎无法将其与我的问题联系起来。我正在运行一个线程:

   let ballGen = BallGenerator()

    run(SKAction.repeatForever(
        SKAction.sequence([
            SKAction.run(ballGen.addBall(size.width, size.height)),
            SKAction.wait(forDuration: 0.7),

            ])
    ))

addBall() function:

addBall()函数:

func addBall(_ screenWidth: CGFloat, _ screenHeight: CGFloat) {

    // code

}

on the line where it runs ballGen.addBall() it gives the error:

在它运行ballGen.addBall()的行上它给出了错误:

cannot convert value of type '()' to expected argument '() -> void'

无法将'()'类型的值转换为预期的参数'() - > void'

What is going wrong here?

这里出了什么问题?

1 个解决方案

#1


1  

Your addBall function is not returning anything. You should do it like this:

你的addBall函数没有返回任何东西。你应该这样做:

func addBall(_ screenWidth: CGFloat, _ screenHeight: CGFloat) -> SKAction {

    return SKAction
}

#1


1  

Your addBall function is not returning anything. You should do it like this:

你的addBall函数没有返回任何东西。你应该这样做:

func addBall(_ screenWidth: CGFloat, _ screenHeight: CGFloat) -> SKAction {

    return SKAction
}