Recently I needed to add iOS Widgets to my app Wins. As I discovered, if you are using Core Data and want to share data between your iOS app and widgets, you need to use App Groups. At first, I tried to migrate my database following the solution by D...

Markdown supported · ⌘↵ to post
Thank you very much for this code, I tried with ChatGPT and a YouTube video to create App Groups but only with you I could do the migration. The only problem, which is still small, is that the following line gave me an error because the database was not found:
init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: "iCloud.com.yourDomain.YourAppName’")
It should be only with the model name, ie: NSPersistentCloudKitContainer(name: "YourAppName’")
Rodrigo
Ivan Amakhin
You should reset context before destroy container to don't get crash.
Cannot attach stack overflow link but you can find core data error
"Core data crash when resetting the store: 'Object's persistent store is not reachable from this NSManagedObjectContext's coordinator'"