Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call completionHandler for performFetchWithCompletionHandler in Swift

how can I call the completion Handler for the background fetch in Swift. I do the following:

func application(application: UIApplication,
    performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {

    // Do something

    completionHandler (UIBackgroundFetchResultNoData) // This does not work :(

    return

}

Can you please help me? Thanks,

Tobi

like image 568
Tobias Schmidt Avatar asked Nov 11 '14 19:11

Tobias Schmidt


1 Answers

The enum case is UIBackgroundFetchResult.NoData, so the correct way is:

completionHandler (UIBackgroundFetchResult.NoData)

or even:

completionHandler (.NoData)

because the type can be inferred from the closure signature

Hint: when unsure about a function signature, or enum cases, etc., in Xcode write the type, in this case UIBackgroundFetchResult, and then cmd+click it to go to the definition, or option+click to popup its declaration. That usually helps a lot.

like image 71
Antonio Avatar answered Oct 15 '22 15:10

Antonio