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/b00e97a7b636a68c28cb59fbefde5492 to your computer and use it in GitHub Desktop.
Save kreeger/b00e97a7b636a68c28cb59fbefde5492 to your computer and use it in GitHub Desktop.
Example fetch code for the blog post "Flapjack" on O'Reilly's engineering blog.
// Get every pancake.
let pancakes = dataAccess.mainContext.objects(ofType: Pancake.self)
// Get just the chocolate chip ones.
let pancakes = dataAccess.mainContext.objects(ofType: Pancake.self, attributes: ["flavor": "Chocolate Chip"])
// Create your own.
let pancake = dataAccess.mainContext.create(Pancake.self, attributes: ["flavor": "Rhubarb"])
// Save your changes.
let error = context.persist()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment