简体   繁体   English

错误Nil与预期的参数类型'() - > Void'不兼容

[英]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? 这是为什么?

You should pass the parameter {}: 你应该传递参数{}:

runAction(moveleft, completion: {}) 

as suggested by this answer. 正如这个答案所暗示的那样

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.

相关问题 Nil与预期的参数类型&#39;UIImage&#39;不兼容 - Nil is not compatible with expected argument type 'UIImage' Nil与预期的参数类型UIViewAnimationOptions不兼容 - Nil is not compatible with expected argument type UIViewAnimationOptions Nil与预期的参数类型选择器不兼容 - Nil is not compatible with expected argument type Selector Nil与预期的参数类型&#39;String&#39;不兼容 - Nil is not compatible with expected argument type 'String' Nil与预期的参数类型&#39;NSLayoutAnchor不兼容 <NSLayoutDimention> &#39; - Nil not compatible with expected argument type 'NSLayoutAnchor<NSLayoutDimention>' nil与预期的参数类型'[NSObject:AnyObject]不兼容 - nil is not compatible with the expected argument type '[NSObject : AnyObject]' 如何修复Nil与预期的参数类型&#39;UIColor&#39;不兼容 - How can I fix Nil is not compatible with expected argument type 'UIColor' 无法将类型&#39;(_)-&gt;()&#39;的值转换为预期的参数类型&#39;((Bool,Error?)-&gt; Void)? - Cannot convert value of type '(_) -> ()' to expected argument type '((Bool, Error?) -> Void)?' iOS Swift Amazon S3传输实用程序-零与预期参数类型nsurl不兼容 - IOS Swift Amazon S3 transfer utility- nil is not compatible with expected argument type nsurl 错误:无法将类型&#39;(_,_)-&gt; Void&#39;的值转换为预期的参数类型&#39;(((UIAlertAction)-&gt; Void)? - Error: Cannot convert value of type '(_, _) -> Void' to expected argument type '((UIAlertAction) -> Void)?'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM