Merge pull request #651 from omnivore-app/feature/core-data-app-group

Store sqlite file in app group file container [iOS]
This commit is contained in:
Satindar Dhillon 2022-05-18 13:23:24 -07:00 committed by GitHub
commit b87f068193
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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