Skip to content

Instantly share code, notes, and snippets.

@HereOrCode
Created March 7, 2022 11:16
Show Gist options
  • Save HereOrCode/d7395690b5c3f5f5f88900ee3e10521e to your computer and use it in GitHub Desktop.
Save HereOrCode/d7395690b5c3f5f5f88900ee3e10521e to your computer and use it in GitHub Desktop.
CoreData fetchRequest methods
//  here are the five different ways to set up a fetch request so you’re not caught by surprise:
// 1
let fetchRequest1 = NSFetchRequest<Venue>()
let entity = 
  NSEntityDescription.entity(forEntityName: "Venue",
                             in: managedContext)!
fetchRequest1.entity = entity

// 2
let fetchRequest2 = NSFetchRequest<Venue>(entityName: "Venue")

// 3
let fetchRequest3: NSFetchRequest<Venue> = Venue.fetchRequest()

// 4
let fetchRequest4 = 
  managedObjectModel.fetchRequestTemplate(forName: "venueFR")

// 5
let fetchRequest5 =
  managedObjectModel.fetchRequestFromTemplate(
    withName: "venueFR",
    substitutionVariables: ["NAME" : "Vivi Bubble Tea"])

rTgR09

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment