ios - 无法将类型 '() -> Void' 的值转换为预期的参数类型 '(() -> Void)?'

标签 ios swift swift3

我试图在尝试转换为 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/

相关文章:

未保存整数的 IOS Swift 值

ios - APN 用于开发而非分发

ios - Swift 中的计算器

ios - 带有大标题的 UINavigationbar 弹出动画故障

arrays - 快速将字符串更改为变量

ios - 如何以编程方式创建多个按钮和操作?

swift - 以编程方式添加约束会导致崩溃

ios - WatchKit:与包含的 iOS 应用程序直接通信

ios - iOS 应用程序的 Firebase 3.7.0 上的链接错误

iPhone应用程序崩溃日志 - 如何获取崩溃日志中的类名和方法名?