Code example of how I get a MOC, set entity attributes, and save MOC:
let newCategory = Category(context: CoreDataStack.getContext())
newCategory.attribute1 = textField.text!
newCategory.attribute2 = true
CoreDataStack.saveContext()
getContext() simply returns a persistentContainer.viewContext and saveContext() is a basic:
if context.hasChanges {
						do {
								try context.save()
								
						} catch let error as NSError {
								let nserror = error as NSError
								fatalError("Unresolved error when saving MOC: \(nserror), \(nserror.userInfo)")								
						}
}