Complete the code to create a Core Data context from the persistent container.
let context = persistentContainer.[1]The viewContext is the main managed object context used for UI updates in Core Data.
Complete the code to save changes in the Core Data context.
do {
try context.[1]()
} catch {
print("Save failed")
}Calling save() on the context commits changes to the persistent store.
Fix the error in fetching Core Data objects by completing the fetch request code.
let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: [1]) let results = try context.fetch(fetchRequest)
The entity name must be a string literal matching the Core Data model entity name exactly, including case.
Fill both blanks to create a new managed object and set its attribute.
let entity = NSEntityDescription.entity(forEntityName: [1], in: context)! let newObject = NSManagedObject(entity: entity, insertInto: [2]) newObject.setValue("John", forKey: "name")
Use the entity name as a string and insert the new object into the current context.
Fill all three blanks to filter fetch results by a condition.
let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: [1]) fetchRequest.predicate = NSPredicate(format: "[2] == %@", [3]) let results = try context.fetch(fetchRequest)
The fetch request uses the entity name "Person" and filters where the attribute "age" equals 30.