I have decided to make a change in my app. My app is arranged around “projects”. Each project is a set of work someone does. Previously, I kept all projects in a single CoreData instance. That works fine but has some disadvantages. Mainly I want the user to be able to open and close projects much like they would open or close a document with a word processor.
I am working on giving the user the ability to specify a Core Data instance (sqllite) to open, save, backup, etc. So far the user can create a new project - the program will create a “bundle/package” folder at the location chosen by NSSavePanel. Inside the bundle are the SQLLite files needed by Core Data, and open that Core Data instance and display the user interface.
To do this requires that it delays dealing with the CoreData instance from the app startup. When the users decides to open a recent project or create a new one I need to ensure the previous (if any) Persistent Store is closed and no data is lost - (save context, reset?). Each project will have its own set of SQLLite files in the bundle (it appears as a single file instead of a folder).
I need to close one instance and then open/create a new one while the program is running.
I am making some progress, but it is complicated (to me - being a newbie). For instance, the standard method of initialization of the PersistenceController/PersistenceContainer at startup and placing those in the environment works well - it seems they are singletons and immutable. So, I am working on using a class that contains those and publishing it, then I can update them.
What I am asking for is if ANYONE has any suggestions on best practices when an app switches open/close/create etc Core Data instances on the fly, I would appreciate it. If anyone has any links to projects that actually do this, it would be great to see what someone else came up with.
I am working on giving the user the ability to specify a Core Data instance (sqllite) to open, save, backup, etc. So far the user can create a new project - the program will create a “bundle/package” folder at the location chosen by NSSavePanel. Inside the bundle are the SQLLite files needed by Core Data, and open that Core Data instance and display the user interface.
To do this requires that it delays dealing with the CoreData instance from the app startup. When the users decides to open a recent project or create a new one I need to ensure the previous (if any) Persistent Store is closed and no data is lost - (save context, reset?). Each project will have its own set of SQLLite files in the bundle (it appears as a single file instead of a folder).
I need to close one instance and then open/create a new one while the program is running.
I am making some progress, but it is complicated (to me - being a newbie). For instance, the standard method of initialization of the PersistenceController/PersistenceContainer at startup and placing those in the environment works well - it seems they are singletons and immutable. So, I am working on using a class that contains those and publishing it, then I can update them.
What I am asking for is if ANYONE has any suggestions on best practices when an app switches open/close/create etc Core Data instances on the fly, I would appreciate it. If anyone has any links to projects that actually do this, it would be great to see what someone else came up with.