我是今天的新扩展,我有这个警告,有人知道如何匹配可选的要求吗?
实例方法'widgetPerformUpdate(completionHandler:)‘几乎匹配协议'NCWidgetProviding’的可选需求'widgetPerformUpdate(completionHandler:)‘
func widgetPerformUpdate(completionHandler: ((NCUpdateResult) -> Void)) {
// Perform any setup necessary in order to update the view.
// If an error is encountered, use NCUpdateResult.Failed
// If there's no update required, use NCUpdateResult.NoData
// If there's an update, use NCUpdateResult.NewData
let result = performFetch()
if result == .newData{
tableView.reloadData()
self.preferredContentSize = tableView.contentSize
}
completionHandler(result)
}发布于 2016-10-27 04:08:06
在参数类型之前写入@escaping,以指示闭包允许转义。
func widgetPerformUpdate(completionHandler: (@escaping(NCUpdateResult) -> Void)) {
// Perform any setup necessary in order to update the view.
// If an error is encountered, use NCUpdateResult.Failed
// If there's no update required, use NCUpdateResult.NoData
// If there's an update, use NCUpdateResult.NewData
let result = performFetch()
if result == .newData{
tableView.reloadData()
self.preferredContentSize = tableView.contentSize
}
completionHandler(result)
}该函数基本上以闭包参数作为完成处理程序。函数在开始操作后返回,但在操作完成后才会调用闭包--闭包需要转义,稍后才调用。
https://stackoverflow.com/questions/40166939
复制相似问题