smb 能否解释一下问题是什么,我应该如何修改我的代码?
我需要过滤CKRecord
s 返回自CloudKit
.
override func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
let defaultContainer = CKContainer.defaultContainer()
let publicDatabase = defaultContainer.publicCloudDatabase
let myfunc2 = myfunc(names, { (records: [CKRecord], error: NSError) in
if error == nil {
let records2 = records.filter($0.value > sourceIndexPath.row && $0.value < destinationIndexPath.row)
let mro = CKModifyRecordsOperation(recordsToSave: [], recordIDsToDelete: [])
} else {
}
})
有两种编写闭包的方法:使用显式参数名称,或者将参数引用为 $0、$1 等。
例如,以下两件事是等价的:
// implicit argument names, $0 and $1
let x = reduce(1...5, 0) { $0 + $1 }
// explicit argument names i and j
let y = reduce(1...5, 0) { i, j in i + j }
但你不能混合这些东西——要么你命名参数,要么使用$n
。你不能两者兼而有之:
// name the arguments, but still use $0 and $1
let x = reduce(1...5, 0) { $0 + $1 }
// compiler error: Anonymous closure arguments cannot be used
// inside a closure that has explicit arguments
在你的例子中,看起来你忘记了提供一个闭包filter
方法。这意味着您的$0
不在没有参数的新闭包内 - 所以 Swift 编译器认为你的$0
指的是外部闭包,将其参数显式命名为records
and error
。所以它抱怨你不能将参数称为$0
在具有显式参数名称的闭包内。
(解决方法当然是实际提供一个闭包filter
即替换你的()
with {}
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)