store sqlite file if app group file container

This commit is contained in:
Satindar Dhillon 2022-05-18 09:37:52 -07:00
parent d9174f48df
commit 1f0a24ce18

View file

@ -12,6 +12,13 @@ public class PersistentContainer: NSPersistentContainer {
let model = NSManagedObjectModel(contentsOf: modelURL)!
let container = PersistentContainer(name: "DataModel", managedObjectModel: model)
// Store the sqlite file in the app group container.
// This allows shared access for app and app extensions.
let appGroupID = "group.app.omnivoreapp"
let appGroupContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupID)
let appGroupContainerURL = appGroupContainer?.appendingPathComponent("store.sqlite")
container.persistentStoreDescriptions.first!.url = appGroupContainerURL
container.viewContext.automaticallyMergesChangesFromParent = true
container.viewContext.name = "viewContext"
container.viewContext.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump