【发布时间】:2017-07-22 11:47:20
【问题描述】:
我有一个迭代类别类列表的方法,最后从所有类别中返回项目。 简单的代码如下所示:
func iterateMyCategoriesItems(item:(_ category:Category) -> Void)
{
for category in allCategories
{
item(category)
}
}
使用时:
iterateMyCategoriesItems { (category) in
// doing something here with every category...
}
到目前为止一切顺利,但现在我想为这个方法添加一个可选的完成,所以我将代码更改为:
func iterateMyCategoriesItems(item:(_ category:Category) -> Void, _ completion:(() -> Void)? = nil)
{
for category in allCategories
{
item(category)
}
completion?()
}
但是现在当我尝试使用这样的方法时:
iterateMyCategoriesItems { (category) in
// doing something here with every category...
}
编译器显示错误:
调用中的参数“item”缺少参数。
那么,我做错了什么?
【问题讨论】: