Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use NSPersistentContainer with NSPersistentDocument

Nowadays all core data examples are iOS examples, so there isn't much guidance for macOS since the interesting changes to core data in macOS 10.12. But I would like to see how the NSPersistentContainer is supposed to work with a multi-document setup. Who has a good tutorial etc.? How is the stack now supposed to work? Many thanks in advance!

like image 288
Wizard of Kneup Avatar asked May 31 '26 16:05

Wizard of Kneup


1 Answers

It doesn't seem that NSPersistentContainer is relevant to apps using NSPersistentDocument. It's not used because it's not needed.

The main purpose of NSPersistentContainer is to handle setting up the Core Data stack and creating managed object contexts. But NSPersistentDocument already does that. It also has properties that allow the same things NSPersistentContainer provides after setting up the stack. For example, if you need a new managed object context, get the coordinator using managedObjectContext.persistentStoreCoordinator and then just instantiate a new context object using that coordinator.

like image 148
Tom Harrington Avatar answered Jun 03 '26 08:06

Tom Harrington



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!