|
I have made the following code to basically play around with haptics: LibraryView.swift
And NewCustomHaptic.swift, which is a sheet to add a new class CustomHaptic:
and
every single time i run it, i get " Query encountered an error: Error Domain=NSCocoaErrorDomain Code=256 "The file “default.store” couldn’t be opened." " in the console. And when I press done on the sheet, i get the same error. Thank you for helping |
|
The issue appears to lay in the Query for DefaultHaptic:
you didn't provide code for this model so when trying to recreate your issue I temporarily disabled it. With it disabled, and with the content view as shown below, I was unable to recreate the issue you've identified in a simulator.
If you share the additional model details I'm happy to try and reproduce it again. Hope this at least gives you some direction in the meantime. |
|
It's just a normal SwiftData as far as i know:
|
|
I also changed a few things: NewCustomHaptic.swift
and LibraryView.swift
I basically changed logic to make a new variable of the class, pass it in as a @Binding, then take it back and insert that in to the model. However upon running on a real iPhone, the console said "SwiftData/ModelContainer.swift:144: Fatal error: failed to find a currently active container for CustomHaptic" This issue seems fixable. Apart from this, are there any better ways to use SwiftData? |
|
your new issue is likely from the code in your tab view here:
the items should go together in a single instance of modelcontainer
also if you've made any changes to your data model in between running your build on device (simulator or real) it can cause a similar crash. To avoid it you can use versioning or alternatively delete the app, and therefore any conflicting data, from the device. |
|
Oh wow thank you so much i literally spent three hours trying to see what was wrong and this was it? i would never have thought that. Thank you |
|
happy to hear it worked! I'm new to swift/coding in general so I've done similar and spent hours troubleshooting only to discover a hidden error in one line of seemingly inconsequential code. Done it a lot of this while learning SwiftData these past few months 😅 Happy coding! |
SPONSORED Debug 10x faster with Proxyman. Your ultimate tool to capture HTTPs requests/ responses, natively built for iPhone and macOS. You’d be surprised how much you can learn about any system by watching what it does over the network.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.