我试图在尝试转换为 Swift 3 时修复我的结局错误,但是我不确定为什么会收到错误
Cannot convert value of type '() -> Void' to expected argument type '(() -> Void)?'
为了
CATransaction.setCompletionBlock(completion)
功能齐全
fileprivate func deleteRowsAtIndexPaths(_ indexPaths: [IndexPath], withRowAnimation animation: UITableViewRowAnimation, duration: TimeInterval, completion:() -> Void) {
CATransaction.begin()
CATransaction.setCompletionBlock(completion) //Error
UIView.animate(withDuration: duration) { () -> Void in
self.deleteRows(at: indexPaths, with: animation)
}
CATransaction.commit()
}
有谁知道我为什么会收到这个错误以及如何解决该错误?
最佳答案
请查看the latest reference当您在将代码迁移到 Swift 3 时发现一些奇怪的事情。
Declaration
class func setCompletionBlock(_ block: (@escaping () -> Void)?)
尝试将方法头的这一部分 completion:() -> Void
更改为:
completion: @escaping () -> Void
关于ios - 无法将类型 '() -> Void' 的值转换为预期的参数类型 '(() -> Void)?',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39349883/