From 1f0a24ce18e6416cee284ad105db29c93c955b51 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Wed, 18 May 2022 09:37:52 -0700 Subject: [PATCH] store sqlite file if app group file container --- .../Sources/Models/CoreData/StorageProvider.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apple/OmnivoreKit/Sources/Models/CoreData/StorageProvider.swift b/apple/OmnivoreKit/Sources/Models/CoreData/StorageProvider.swift index 43c958f57..374770177 100644 --- a/apple/OmnivoreKit/Sources/Models/CoreData/StorageProvider.swift +++ b/apple/OmnivoreKit/Sources/Models/CoreData/StorageProvider.swift @@ -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