Has anyone else used #SwiftData based DocumentGroup in #SwiftUI?
It is pretty convenient compared to rolling your own storage solution. I’m able to create a custom file extension and I can keep all SwiftData properties non-optional which cannot be done with CloudKit.
However, I have had it happen a couple times where the file will refuse to open on #iPadOS after having it opened on #macOS, which is a cause for concern because I cannot afford data loss. Especially since it doesn’t appear to be possible to create backups of the file, or prevent it from being opened on more than one device, etc.
I am not sure what causes this as theres no errors in Xcode when it happens… Any ideas why that might be?
@JTostitos I have used documents groups but not with swift data. Personally I was burn one to many times with bugs in swift data back when it first shipped to trust it. I prefer to write json or for perf sensitive/large write raw bytes.
@JTostitos The only time I tried this was with a sample app from Apple. It built but then crashed every time I ran it. Admittedly this was when SwiftData was first released but it put me off the entire concept.
@troz Welp, guess I may ditch SwiftData for this then. Bummer.
Do you know of any resources that show how to perhaps make DocumentGroup work with a JSON file? I heard JSON is less susceptible to crashing your app because if a new key is added it just merges it and its values to the existing file. Is that true?
@JTostitos I don’t know of any resources but I would create a new document app project without any database and experiment with the supplied read and write methods.