我正在将我的代码从Swift 2迁移到Swift 4,但我不确定为什么会收到此错误:
无法转换类型'(_) - >的值()'到预期的参数类型'(() - > Void)?'
这是我的功能:
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)
}
}
有人知道我为什么会这样做以及如何解决错误?
答案 0 :(得分:3)
从行中删除_ in
:
self.presentingViewController?.dismiss(animated: true, completion: {_ in
基于dismiss
的{{3}},completion
回调不接受任何参数。