2016-10-21 5 views
1

今日の拡張機能では新しいですが、この警告があります。インスタンスメソッド 'widgetPerformUpdate(completionHandler :)'は、オプションの要件とほぼ一致しています 'widgetPerformUpdate(completionHandler :)'

インスタンスメソッド 'widgetPerformUpdate(completionHandlerは:)' ほぼオプションの要件 'widgetPerformUpdate(completionHandler :)' プロトコルの 'にマッチNCWidgetProviding'

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) 
} 
+0

'func widgetPerformUpdate(completionHandler:@escaping(NCUpdateResult) - > void){' – rmaddy

+0

@rmaddy、それが動作します! –

答えて

0

があることを示すために、パラメータの型の前に@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) 
} 

この関数は、基本的にクロージャ引数を補完ハンドラとして受け取ります。この関数は操作を開始した後に戻りますが、操作が完了するまでクロージャは呼び出されません。クロージャはエスケープする必要があり、後で呼び出される必要があります。

関連する問題