0

I'm following this solution to migrate the Core Data database to AppGroup and always "persistentStore(for: oldStoreURL)" returns "nil". The URL is correct and the file exist in the path. Any ideas?

if let url = defaultURL, url.absoluteString != storeURL.absoluteString {
        let coordinator = container.persistentStoreCoordinator
        if let oldStore = coordinator.persistentStore(for: url) {   // oldStore returns nil
            do {
                try coordinator.migratePersistentStore(oldStore, to: storeURL, options: nil, withType: NSSQLiteStoreType)
            } catch {
                print(error.localizedDescription)
            }

            // delete old store
            let fileCoordinator = NSFileCoordinator(filePresenter: nil)
            fileCoordinator.coordinate(writingItemAt: url, options: .forDeleting, error: nil, byAccessor: { url in
                do {
                    try FileManager.default.removeItem(at: url)
                } catch {
                    print(error.localizedDescription)
                }
            })
        }
    }
LucasC
  • 43
  • 5

0 Answers0