简体   繁体   中英

Cannot convert value of type '() -> Void' to expected argument type '(() -> Void)?'

I am trying to fix my finale error whilst trying to convert to Swift 3, however I am unsure why I am getting the error

Cannot convert value of type '() -> Void' to expected argument type '(() -> Void)?'

For

 CATransaction.setCompletionBlock(completion)

Complete Function

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()
}

Does anybody know why I am getting this and how I can resolve the error ?

Please check the latest reference when you find something odd in migrating your code to Swift 3.

Declaration

 class func setCompletionBlock(_ block: (@escaping () -> Void)?) 

Try changing this part of your method header completion:() -> Void to this:

completion: @escaping () -> Void

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM