How to call completionHandler for performFetchWithCompletionHandler in Swift

自古美人都是妖i 提交于 2020-02-23 10:07:48

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/26873270/how-to-call-completionhandler-for-performfetchwithcompletionhandler-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!