Post

Replies

Boosts

Views

Activity

Reply to Error when running a modelContext rollback
Hi - I am getting the same error, but on modelContext.delete(). I went through checking all the relationship ids, and they are all fine. All models seem to be registered and can be accessed through relationships, fetches or @Query. . I have had some success with SwiftData, using in a semi-production app for about a year. I have never seen this error message before. This seems like a new bug to me.
May ’25
Reply to error: the replacement path doesn't exist:
I think I have made some progress with this by introducing manual saves when working on the model, so for example, instead of: selectedItem = item I have replaced with: do { try modelContext.transaction { selectedItem = item } catch { print("unable to save change due to error \(error)") } Items are now successfully persisting, and the error: SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData. Seems to have gone away. It seems like the error was something to do with the way that changes are stashed and saved in the background by SwiftData, I am not an expert but my best guess is that it is related to the recent changes in concurrency architecture. I have also found SwiftData to be much more reliable if you work directly on elements derived from @Query in the view, rather than trying to save on @Bindable from a parent. I pass the UUID around the views and then filter the arrray from @Query for the id.
Sep ’24
Reply to error: the replacement path doesn't exist:
I have a SwiftData document-based app with iCloud documents enabled, and lots of one-to-many @model relationships. I have the same issue as reported, and I am getting the error: Publishing changes from background threads is not allowed; make sure to publish values from the main thread I also get a crash shortly after with the breakpoint message: SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData. I wonder if the two errors are related. I have not tested on the simulator, but have tested on iPad Pro M1 and iPhone 12 Both errors have only appeared in ios18, and the app has been running great for many months in ios17 with no crashes. Suddenly ios18 is released and the entire app is broken. Grrrrr.
Sep ’24
Reply to Document-based SwiftData apps fail to identify a store on iPad?
I have the same issue, it has completely broken my project. I have upgraded to Swift 6, but that didnt help. I have tried manually creating a container, but the container is not unique to the document. I have a large data model with many relationships, it stores simple data and image data. It has been working great for a year, and then completely crashes on IOS18! I am at a loss, please help!
Sep ’24
Reply to Xcode 15 beta 5 missing cascade property option in @Relationship(.cascade) error.
It seems that you can make all of the variables optional where they are declared in the @Model class (eg var variable: String?), and then use nil coalescing to unwrap when the properties are called (?? ""), but then you get a compile time error when you call the parameter from @Bindable in the View using a binding. The below will not compile, even with the ?? "". struct egView: View { @Bindable var VM: ViewModel var body: some View { ButtonStruct(Variable: $VM.variable ?? "" ) } Performing nil coalescing in the ButtonStruct doesnt seem to work either, so I am stumped.
Aug ’23
Reply to SwiftData Fatal error: failed to find a currently active container
I had the same issue after the XCode beta 5 update. My issue has three models in an array, so a slightly different solution: import SwiftData import SwiftUI @main struct SurvAIApp: App { let modelContainer: ModelContainer init() { do { modelContainer = try ModelContainer(for: [ViewModel1.self,ViewModel2.self, ViewModel3.self]) } catch { fatalError("Could not initialize ModelContainer") } } var body: some Scene { WindowGroup { NavigationStack { ContentView() } .modelContainer(modelContainer ) } }
Jul ’23
Reply to Error when running a modelContext rollback
@axel.mr Thank you for you help, but no I dont think it is the same issue. I am acting on a fetched model on the main actor and main context. The error message is identical to yours. We could really do with some additional debugging outut to see exactly what key is the problem.
Replies
Boosts
Views
Activity
May ’25
Reply to Error when running a modelContext rollback
Hi - I am getting the same error, but on modelContext.delete(). I went through checking all the relationship ids, and they are all fine. All models seem to be registered and can be accessed through relationships, fetches or @Query. . I have had some success with SwiftData, using in a semi-production app for about a year. I have never seen this error message before. This seems like a new bug to me.
Replies
Boosts
Views
Activity
May ’25
Reply to SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData._KKMDBackingData<Presents_2024.Item> from [:]
I have had some success by implementing manual saves using modelContext.transaction() whenever interacting with the model.
Replies
Boosts
Views
Activity
Sep ’24
Reply to error: the replacement path doesn't exist:
I think I have made some progress with this by introducing manual saves when working on the model, so for example, instead of: selectedItem = item I have replaced with: do { try modelContext.transaction { selectedItem = item } catch { print("unable to save change due to error \(error)") } Items are now successfully persisting, and the error: SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData. Seems to have gone away. It seems like the error was something to do with the way that changes are stashed and saved in the background by SwiftData, I am not an expert but my best guess is that it is related to the recent changes in concurrency architecture. I have also found SwiftData to be much more reliable if you work directly on elements derived from @Query in the view, rather than trying to save on @Bindable from a parent. I pass the UUID around the views and then filter the arrray from @Query for the id.
Replies
Boosts
Views
Activity
Sep ’24
Reply to error: the replacement path doesn't exist:
I have a SwiftData document-based app with iCloud documents enabled, and lots of one-to-many @model relationships. I have the same issue as reported, and I am getting the error: Publishing changes from background threads is not allowed; make sure to publish values from the main thread I also get a crash shortly after with the breakpoint message: SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData. I wonder if the two errors are related. I have not tested on the simulator, but have tested on iPad Pro M1 and iPhone 12 Both errors have only appeared in ios18, and the app has been running great for many months in ios17 with no crashes. Suddenly ios18 is released and the entire app is broken. Grrrrr.
Replies
Boosts
Views
Activity
Sep ’24
Reply to SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData._KKMDBackingData<Presents_2024.Item> from [:]
I have the same issue. Has anyone found a workaround?
Replies
Boosts
Views
Activity
Sep ’24
Reply to Document-based SwiftData apps fail to identify a store on iPad?
I have the same issue, it has completely broken my project. I have upgraded to Swift 6, but that didnt help. I have tried manually creating a container, but the container is not unique to the document. I have a large data model with many relationships, it stores simple data and image data. It has been working great for a year, and then completely crashes on IOS18! I am at a loss, please help!
Replies
Boosts
Views
Activity
Sep ’24
Reply to How to define icons for exported type identifier?
You can drag a .png file straight into the little window that says "Add exported type identifier...", how to get your app to actually display these is a different matter....
Replies
Boosts
Views
Activity
Apr ’24
Reply to SwiftData CloudKit integration seems to log out or deregister
My issue is now fixed. It was that I had not deployed schema changes from development to production containers in the CloudKit console. The cause of logging out intermittently might be a response to finding an inconsistency between the data model and container.
Replies
Boosts
Views
Activity
Dec ’23
Reply to Xcode 15.0 Beta 5, Symbol not found: _$s9SwiftData014DefaultBackingB0C3forACyxGxm_tcfC
From the release notes: Known Issues: Apps using SwiftData that are built with Xcode 15 beta 6 have known issues when running on iOS 17 beta 6. (113915428): Workaround: Use iOS 17 Beta 5 with Xcode Beta 6. Correct me if I am wrong, but I dont think we can easily downgrade in IOS, so I will be waiting for Beta 7 of Xcode.
Replies
Boosts
Views
Activity
Aug ’23
Reply to Xcode 15 beta 5 missing cascade property option in @Relationship(.cascade) error.
It seems that you can make all of the variables optional where they are declared in the @Model class (eg var variable: String?), and then use nil coalescing to unwrap when the properties are called (?? ""), but then you get a compile time error when you call the parameter from @Bindable in the View using a binding. The below will not compile, even with the ?? "". struct egView: View { @Bindable var VM: ViewModel var body: some View { ButtonStruct(Variable: $VM.variable ?? "" ) } Performing nil coalescing in the ButtonStruct doesnt seem to work either, so I am stumped.
Replies
Boosts
Views
Activity
Aug ’23
Reply to SwiftData Fatal error: failed to find a currently active container
I had the same issue after the XCode beta 5 update. My issue has three models in an array, so a slightly different solution: import SwiftData import SwiftUI @main struct SurvAIApp: App { let modelContainer: ModelContainer init() { do { modelContainer = try ModelContainer(for: [ViewModel1.self,ViewModel2.self, ViewModel3.self]) } catch { fatalError("Could not initialize ModelContainer") } } var body: some Scene { WindowGroup { NavigationStack { ContentView() } .modelContainer(modelContainer ) } }
Replies
Boosts
Views
Activity
Jul ’23