Hello pawello2222,
Sorry for asking you question via Github, just created a SF account and have no permission to add comment.
I am trying to show core data with widget, and I have viewed lots of your answers on the SF. I am currently using the Presistence which is generated by the Xcode when I select the Swift lifecycle.
I set Target Membership of Presistence.swift to the host app and the widget, but I don't implement the coreDataStack. I declare one in the root view of the host app and one in the coreDataManger. The coreDataManager is in this post [https://stackoverflow.com/questions/63991081/how-to-ensure-widgetkit-view-shows-correct-results-from-fetchrequest]
After adding the host app and the widget to a same app group, the widget can show the core data which I fetch. But it also break the iCloud sync. Before I did this, the iCloud sync is working. Would you like to help me? Must I implement a coreDataStack?
`
struct PersistenceController {
// MARK controller
static let shared = PersistenceController()
// MARK container
let container: NSPersistentContainer
// MARK init
init(inMemory: Bool = false) {
container = NSPersistentCloudKitContainer(name: "database_app")
if inMemory {
container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
}
let storeURL = AppGroup.facts.containerURL.appendingPathComponent("database_app.sqlite")
let description = NSPersistentStoreDescription(url: storeURL)
let description1 = container.persistentStoreDescriptions.first
description1?.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
container.persistentStoreDescriptions = [description]
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
// MARK enable iCloud
container.viewContext.automaticallyMergesChangesFromParent = true
container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
}
}
`
And in the root view of the host app and the coreDataManager, I declare like this:
let persistenceController = PersistenceController.shared