swift - 是否可以在闭包中使用可变参数?
问题描述
翻新问题
Swift:结合使用可变参数和闭包
是否可以使用可变参数进行闭包?
func this(_ hello: (Int...) -> ()) {}
func that(_ yeah: Int...) {}
以下是有效的:this(that)
以下是无效的:
this { foo in }
, this { _ in }
,this { }
我收到此错误:
Cannot convert value of type '(_) -> ()' to expected argument type '(Int...) -> ()'
我什至将所有更改Int...
为Void...
我得到了相同的结果
但是
附加警告
When calling this function in Swift 4 or later, you must pass a '()' tuple; did you mean for the input type to be '()'? Replace '(Void...)' with '()'
,将 Void... 替换为 ()... 成功了
简化问题
let _: (()...) -> () = { _ in }
导致此错误:
Cannot convert value of type '(_) -> ()' to specified type '(()...) -> ()'
是否可以解决此问题?
解决方案
推荐阅读
- python - 如何在python脚本函数内部的sql查询中传递多个命令行参数或系统参数?
- or-tools - 使用 ortools for python 选择列表的最小值或最大值
- two-factor-authentication - 如何确保 TOTP 的用户密钥有效?
- c# - 如何使对象仅旋转一次 360 度?
- java - 从 Map 中的 Lists 中删除重复的元素
- javascript - b-table 在“取消移动”新行时重新加载嵌套组件(但不是在“推送”时)
- asp.net-core-2.0 - 在 .net core 2.1.6 中将 Microsoft.aspnetcore.all 更改为 Microsoft.NETCore.App 后,UseLibuv 选项消失了
- openshift - oc new-app 的附加步骤。创建自动缩放策略
- ios - Firebase 打印快照工作正常并获取字典,但是当尝试访问单个字段数据时,某些字段返回 nil
- android - 安装Android Studio后如何修复“属性android:layout_width,layout_height和textview不允许”