-1

Referencing question: https://stackoverflow.com/a/24725314/2909692, I have the same application requirements in that I need a series of methods to be called, only after data has been loaded from web.

I have reviewed and researched the answer (summed below), but do not understand how it is to be implemented, what are the parameters that need to be passed?

How is loadShows to be used?

func application(application: UIApplication!, performFetchWithCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)!) {
    loadShows() {
        completionHandler(UIBackgroundFetchResult.NewData)
        println("Background Fetch Complete")
    }
}

func loadShows(completionHandler: (() -> Void)!) {
    //....
    //DO IT
    //....
    completionHandler()
})
Community
  • 1
  • 1
Sauron
  • 6,399
  • 14
  • 71
  • 136

1 Answers1

1

In the func application you can see that they call loadShows().

But they call it with a trailing closure:

loadShows() {
    completionHandler(UIBackgroundFetchResult.NewData)
    println("Background Fetch Complete")
}

It means that the block of code:

{
    completionHandler(UIBackgroundFetchResult.NewData)
    println("Background Fetch Complete")
}

is passed as an argument to the loadShows() function, and this block is executed after the rest of the loadShows() code, when loadShows()'s completionHandler() is called (after "DO IT").

Eric Aya
  • 69,473
  • 35
  • 181
  • 253