I have an iOS app target and watchOS target in my project. In addition, I have the infrastructure for the iOS application, which houses my CoreData model and some classes. In a different structure for the watchOS application, I have the same classes. Now I want to access the same data in the iOS app and watchOS app. I already have an application group that usually stores CoreData. But when I open the application on the watch, there is an empty storage without data, and the phone has a normal store. What mistake did I make? Do you have any tips for me?
I use this code to create persistent storage:
var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
let fileManager = FileManager.default
let url = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "MYGROUP")?.appendingPathComponent("XXX.sqlite")
var error: NSError? = nil
var failureReason = "There was an error creating or loading the application saved data."
var options = [NSMigratePersistentStoresAutomaticallyOption:true, NSInferMappingModelAutomaticallyOption: true]
do {
try coordinator!.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: options)
thank