Persistence framework for Cocoa Touch.
let widget = NSEntityDescription.insertNewObjectForEntityForName(
"Widget", inManagedObjectContext: managedObjectContext)
as! Widget
// then at some point:
try managedObjectContext.save()
let fetchRequest = NSFetchRequest(entityName: "Widget")
let widgets = try managedObjectContext.executeFetchRequest(fetchRequest)
as? [Widget]
let fetchRequest = NSFetchRequest(entityName: "Widget")
fetchRequest.predicate = NSPredicate(format: "widgetId == %@", idToFind)
let widgets = try managedObjectContext.executeFetchRequest(fetchRequest)
as? [Widget]
Individual objects don’t need to be saved; you just need to save the entire managed object context at some point:
try managedObjectContext.save()
managedObjectContext.deleteObject(widget)