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
Thanks a lot for taking the time to share this knowledge, Kris.
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'"