From ed45e5d2e43bca48e1f8b945d288d0943a0b1379 Mon Sep 17 00:00:00 2001 From: Davide Date: Thu, 12 Dec 2024 12:48:58 +0100 Subject: [PATCH] Fix a Core Data crash on Apple TV (#1003) Could not create the Preferences Core Data container in the App Group because sub-directories did not exist. Create them upfront when using App Group URLs. This was not an issue with other Core Data containers because they are stored in the app directories, where "Library/Documents" already exists. --- .../Domain/BundleConfiguration+AppGroup.swift | 8 ++++++-- .../CommonUtils/Business/CoreDataPersistentStore.swift | 4 ---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Library/Sources/CommonLibrary/Domain/BundleConfiguration+AppGroup.swift b/Library/Sources/CommonLibrary/Domain/BundleConfiguration+AppGroup.swift index 5dc30bfd..eb1f6ab8 100644 --- a/Library/Sources/CommonLibrary/Domain/BundleConfiguration+AppGroup.swift +++ b/Library/Sources/CommonLibrary/Domain/BundleConfiguration+AppGroup.swift @@ -44,11 +44,15 @@ extension BundleConfiguration { extension BundleConfiguration { public static var urlForGroupCaches: URL { - appGroupURL.appending(components: "Library", "Caches") + let url = appGroupURL.appending(components: "Library", "Caches") + try? FileManager.default.createDirectory(at: url, withIntermediateDirectories: true) + return url } public static var urlForGroupDocuments: URL { - appGroupURL.appending(components: "Library", "Documents") + let url = appGroupURL.appending(components: "Library", "Documents") + try? FileManager.default.createDirectory(at: url, withIntermediateDirectories: true) + return url } } diff --git a/Library/Sources/CommonUtils/Business/CoreDataPersistentStore.swift b/Library/Sources/CommonUtils/Business/CoreDataPersistentStore.swift index c842897f..b7416905 100644 --- a/Library/Sources/CommonUtils/Business/CoreDataPersistentStore.swift +++ b/Library/Sources/CommonUtils/Business/CoreDataPersistentStore.swift @@ -117,10 +117,6 @@ extension CoreDataPersistentStore { public func backgroundContext() -> NSManagedObjectContext { container.newBackgroundContext() } - - public var coordinator: NSPersistentStoreCoordinator { - container.persistentStoreCoordinator - } } // MARK: Development