I have a SwiftUI + SwiftData (with iCloud) app. The setup code is standard, with schema migrations (mostly lightweight, one custom). Everything works correctly except in one scenario.
When I run a newer version of the app (with an updated schema adding one field + migration) on a device with the previous data container (the usual app version update through TestFlight), I encounter an issue on the first launch. The app crashes on the first "cold" start but runs successfully on subsequent launches.
The error I receive on the first run is:
addPersistentStoreWithType:configuration:URL:options:error: returned error NSCocoaErrorDomain (134060)
NSLocalizedFailureReason : Unable to find a configuration named 'default' in the specified managed object model.
What might be a problem and how to resolve it?
Post
Replies
Boosts
Views
Activity
iPad mini device with iPadOS 17.4.1.
I get this failure on iPad mini device exclusively. I have universal app and I doesn't get this error neither on iPhone or any simulator or macOS. I tried to reset the iPad, still getting the error.
The error happens when I send the app to background from the particular app screen.
Here is the error:
error: Store failed to load.
<NSPersistentStoreDescription: 0x3004b4bd0> (type: SQLite, url: file:///dev/null) with error = Error Domain=NSCocoaErrorDomain Code=134060
"A Core Data error occurred."
UserInfo={NSLocalizedFailureReason=The configuration named 'default' does not contain any entities.} with userInfo {
NSLocalizedFailureReason = "The configuration named 'default' does not contain any entities.";
}
What error says is that it loaded the store from file:///dev/null, which is wrong. Basically it looses the model container which is added via modelContaner modificator to the root view.
The error get caused particularly by the @Environment(\.modelContext) private var modelContext call in the view on which the failure occurs. This view is deep in the view hierarchy, and it get's created in the navigationDestination block.
I fixed the error by supplying modelContainer one more time right on the view:
.navigationDestination(for: File.self) { file in
FileEditor(file: file)
.modelContainer(FolderService.modelContainer)
}
I wonder, why can it loose the model container which is supplied on the root view?
import SwiftUI
import SwiftData
struct ContentView: View {
@Environment(\.modelContext) private var modelContext
@Query private var folders: [Folder]
@State private var currentFolder: Folder?
@State private var currentPath: [Item] = []
var body: some View {
NavigationSplitView {
List(selection: $currentFolder) {
ForEach(folders) { folder in
NavigationLink(value: folder) {
Text(folder.name)
}
}
}
} detail: {
NavigationStack(path: $currentPath) {
if let currentFolder = currentFolder {
List(currentFolder.items) { item in
NavigationLink(value: item) {
Text(item.timestamp.ISO8601Format())
}
}
.navigationDestination(for: Item.self) { item in
Text(item.title)
.background(Color.blue)
}
}
}
}.onOpenURL(perform: { url in // Triggers by clicking on a widget
let descriptor = FetchDescriptor<Folder>()
// Randomly selecting a folder
// In real app the url contains the folder and the item
let folder = try? modelContext.fetch(descriptor).last
if let folder = folder {
currentFolder = folder // Triggering NavigationSplitView navigation works
currentPath = [folder.items.last!] // Triggering NavigationStack navigation doesn't work
}
})
}
private func addFolder() {
// ..
}
}
How to make programmatic navigation work?
I'm receiving this error:
"Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)""
in the console while trying to reverse geocode user's location. The reverse geocoding works OK, I receive the data, but the error in the console bothering me.
Can someone suggest what the code 7 means here and how can I get rid of this error?