To answer your questions it's best to define what a managed object and a managed object context are.
A managed object represents your entities.
A managed object context is best defined by quoting Apple's Core Data Programming Guide:
Think of the managed object context as an intelligent scratch pad. When you fetch objects from a persistent store, you bring temporary copies onto the scratch pad[…]. You can then modify those objects however you like. Unless you actually save those changes, however, the persistent store remains unaltered.
And to answer your last question:
class DataController: ObservableObject { // Create a class that conforms to ObservableObject, by doing so we make sure that it stays alive for the whole life cycle of our app.
let container = NSPersistentContainer(name: "Bookworm") // Uses the name to name the persistent store and to look up the managed object model, we therefore use the same name as in Bookworm.xcdatamodeld
init() { // Initializes the class
container.loadPersistentStores { description, error in // Tells the persistent container to load its persistent stores, by doing so it completes the creation of the core data stack. The method returns a description of the stores and can throw an error.
if let error = error { // Assign error to constant error.
print("Core Data failed to load: \(error.localizedDescription)") // Print out the error message.
}
}
}
}
Here are some great ressources:
https://developer.apple.com/documentation/coredata/core_data_stack
https://www.objc.io/issues/4-core-data/core-data-models-and-model-objects
https://cocoacasts.com/working-with-managed-objects-in-core-data