Xcode 8.1 - NSManagedObjectContext missing in AppDelegate

972 views Asked by At

today im working with a new project created in Xcode 8.1 where i want to use CoreData.

With Xcode 7 there was automatically a NSManagedObjectContext Object in the AppDelegate Class, but in Xcode 8.1 this object is missing.

The NSPersistentStoreCoordinator was changed to NSPersistentContainer.

Now i have no clue how to access the NSManagedObjectContext to write and read values in/from CoreData.

In projects created with Xcode 7 that was the way i've done:

AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
NSManagedObjectContext *context = delegate.managedObjectContext;

NSManagedObject *newEntity = [NSEntityDescription insertNewObjectForEntityForName:@"Entity" inManagedObjectContext:context];

Someone has a solution for me?

1

There are 1 answers

2
Chronisch On BEST ANSWER

I found the solution:

NSManagedObjectContext *context = delegate.persistentContainer.viewContext;

Next time i have to read the documentation twice.