Skip to content

Instantly share code, notes, and snippets.

@kreeger
Created January 8, 2019 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kreeger/f1ac4dd8ab5a41dc80d8d8561872d45e to your computer and use it in GitHub Desktop.
Save kreeger/f1ac4dd8ab5a41dc80d8d8561872d45e to your computer and use it in GitHub Desktop.
Example background execution code for the blog post "Flapjack" on O'Reilly's engineering blog.
dataAccess.performInBackground { [weak self] context in
let pancake = context.create(Pancake.self, attributes: ["flavor": flavor, "radius": radius, "height": height])
let error = context.persist()
DispatchQueue.main.async {
guard let self = self else { return }
let foregroundPancake = self.dataAccess.mainContext.object(ofType: Pancake.self, objectID: pancake.objectID)
completion(foregroundPancake, error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment