[英]error Nil is not compatible with expected argument type '() -> Void'
This code: 这段代码:
runAction(moveleft, completion: nil)
Gives error: 给出错误:
Nil is not compatible with expected argument type '() -> Void'
Nil与预期的参数类型'() - > Void'不兼容
Why is that? 这是为什么?
Not sure if this is new with Swift 4 but I had to use 不确定这是Swift 4的新功能,但我不得不使用
{_ in }
hope this is helpful to someone 希望这对某人有帮助
The function's runAction
completion handler is type of Void
which means, it cant pass nil
as an argument. 函数的
runAction
完成处理程序是Void
类型,这意味着它不能将nil
作为参数传递。
To be able to pass nil
as the argument, change the completions handler type from Void
to Void?
为了能够传递
nil
作为参数,将完成处理程序类型从Void
更改为Void?
. 。
I guess you are referring to SKNode.runAction()
. 我猜你指的是
SKNode.runAction()
。 In that case, completion
is a closure that accepts no argument and return nothing either. 在这种情况下,
completion
是一个不接受任何参数的闭包,也不返回任何内容。 It is to be executed after the action has completed. 它将在动作完成后执行。
There is a runAction
that doesn't require a completion
parameter. 有一个不需要
completion
参数的runAction
。 You should use that: 你应该使用它:
runAction(moveleft)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.