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.
This commit is contained in:
Davide 2024-12-12 12:48:58 +01:00 committed by GitHub
parent 9bf615b0ba
commit ed45e5d2e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 6 deletions

View File

@ -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
}
}

View File

@ -117,10 +117,6 @@ extension CoreDataPersistentStore {
public func backgroundContext() -> NSManagedObjectContext {
container.newBackgroundContext()
}
public var coordinator: NSPersistentStoreCoordinator {
container.persistentStoreCoordinator
}
}
// MARK: Development