I have added all of the relevant code to the App Delegate, and I am able to add to the data model and fetch from the data model in applicationDidFinishLaunchingWithOptions.<
In my case the .xcdatamodeld
was mislabeled in the AppDelegate:
let container = NSPersistentContainer(name: "name of data model")
If the destination view controller is embedded in a NavigationController, the context needs to be set appropriately as follows-
self.mydetailViewController = [[[segue destinationViewController] viewControllers] objectAtIndex:0];
[self.mydetailViewController setManagedObjectContext:self.managedObjectContext];