The following class BackgroundExecutable is to be used to take a function f and return a function f' where f' asks iOS for background execution. f takes a completion closure which it uses to end the background execution.class BackgroundExecutable {  var identifier: UIBackgroundTaskIdentifier  let f: (() -> Void) -> Void  init(f: (completion: () -> Void) -> Void) {    self.f = f    self.identifier = UIBackgroundTaskInvalid  }  func execute() {    let application = UIApplication.sharedApplication()    identifier = application.beginBackgroundTaskWithExpirationHandler {      application.endBackgroundTask(self.identifier)    }    f(endBackgroundTask)  }  func endBackgroundTask() {    UIApplication.sharedApplication().endBackgroundTask(identifier)  }}func backgroundExecutable(f: (() -> Void) -> Void) -> (() -> Void) {  let b = BackgroundExecutable(f: f)  return b.execute}Usage:func F(completion: () -> Void) {  println(F Called)  completion()}let newF = backgroundExecutable(F)
Background execution in iOS
ios;swift