I'm trying to migrate a existing core data db into an app group so that it can be accessed by an apple watch.
So far i have tried
func migrateStore() {
persistentContainer = NSPersistentContainer(name: "Diamond_Painting_Logbook")
persistentContainer.loadPersistentStores { (description, error) in
if let error = error {
fatalError("Could not create CoreData store: \(error)")
}
var nURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.Desbrina.dpl.Diamond-Painting-Logbook.shared")
nURL = nURL?.appendingPathComponent("Diamond_Painting_Logbook.sqlite")
if let newURL = nURL {
do {
let psc = self.persistentContainer.persistentStoreCoordinator
let store = psc.persistentStores[0]
NSLog("7 *****************")
try psc.migratePersistentStore(store, to: newURL, options: nil, withType: NSSQLiteStoreType)
NSLog("8 *****************")
} catch {
}
}
}
}
Its throwing an error on the line.
try psc.migratePersistentStore(store, to: newURL, options: nil, withType: NSSQLiteStoreType)
I'm asuming its because the destination file doesn't exist.
2019-11-23 19:55:45.132081+0000 Diamond Painting Logbook[6707:1813609] 7 *****************
2019-11-23 19:55:45.132863+0000 Diamond Painting Logbook[6707:1813609] [logging-persist] cannot open file at line 43353 of [378230ae7f]
2019-11-23 19:55:45.132901+0000 Diamond Painting Logbook[6707:1813609] [logging-persist] os_unix.c:43353: (0) open(/private/var/mobile/Containers/Shared/AppGroup/BF375BFE-4AF0-4F78-BDEE-C4A4A12493B3/Diamond_Painting_Logbook.sqlite) - Undefined error: 0
2019-11-23 19:55:45.132917+0000 Diamond Painting Logbook[6707:1813609] [logging] API call with unopened database connection pointer
2019-11-23 19:55:45.132929+0000 Diamond Painting Logbook[6707:1813609] [logging] misuse at line 162611 of [378230ae7f]
2019-11-23 19:55:45.133370+0000 Diamond Painting Logbook[6707:1813609] [error] error: -addPersistentStoreWithType:SQLite configuration:PF_DEFAULT_CONFIGURATION_NAME URL:file:///private/var/mobile/Containers/Shared/AppGroup/BF375BFE-4AF0-4F78-BDEE-C4A4A12493B3/Diamond_Painting_Logbook.sqlite/ options:{
NSPersistentStoreRemoveUbiquitousMetadataOption = 1;
} ... returned error NSCocoaErrorDomain(256) with userInfo dictionary {
NSFilePath = "/private/var/mobile/Containers/Shared/AppGroup/BF375BFE-4AF0-4F78-BDEE-C4A4A12493B3/Diamond_Painting_Logbook.sqlite";
NSSQLiteErrorDomain = 14;
}
CoreData: error: -addPersistentStoreWithType:SQLite configuration:PF_DEFAULT_CONFIGURATION_NAME URL:file:///private/var/mobile/Containers/Shared/AppGroup/BF375BFE-4AF0-4F78-BDEE-C4A4A12493B3/Diamond_Painting_Logbook.sqlite/ options:{
NSPersistentStoreRemoveUbiquitousMetadataOption = 1;
} ... returned error NSCocoaErrorDomain(256) with userInfo dictionary {
NSFilePath = "/private/var/mobile/Containers/Shared/AppGroup/BF375BFE-4AF0-4F78-BDEE-C4A4A12493B3/Diamond_Painting_Logbook.sqlite";
NSSQLiteErrorDomain = 14;
}