简体   繁体   中英

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

I am migrating my code from Swift 2 to Swift 4, however I am not sure why I am getting this error:

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

This is my function:

fileprivate func navigateToTagFriends(completion: @escaping (_ taggedUsers : [Athlete]?) -> Void) {
    // Tag Users when item is original content
    if self.parentContent == nil {
        self.state = .finished // Mark as finished so friends operation will execute
        if let tagController = UIStoryboard(type: .Capture).instantiateInitialViewController() as? TagViewController {
            tagController.tagCompletionBlock = { taggedUsers in
                self.presentingViewController?.dismiss(animated: true, completion: {_ in
                    if let processingView = Bundle.main.loadNibNamed("ProcessingView", owner: self, options: nil)?[0] as? UIView {
                        let size = self.presentingViewController?.view.frame.size
                        processingView.frame = CGRect(x: 0, y: 0, width: size?.width ?? 0, height: size?.height ?? 0)
                        self.processingView = processingView
                        self.presentingViewController?.view.addSubview(processingView)
                    }
                    completion(taggedUsers)

                })
            }
            tagController.cancelBlock = {
                self.presentingViewController?.dismiss(animated: true, completion: nil)
            }
            tagController.transitioningDelegate = self
            self.presentingViewController?.present(tagController, animated: true, completion: nil)
        }
    } else {
        completion(nil)
    }

}

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

Remove _ in from the line:

self.presentingViewController?.dismiss(animated: true, completion: {_ in

Based on docs of dismiss , the completion callback does not accept any parameter.

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