swiftuiswiftdatadocument-baseddocumentgroup

DocumentGroup with SwiftData BUG!!!!! (modelContext cannot save and querry)


This is a critical bug with Document-Based Apps (SwiftData). If you download the WWDC 2023 sample code for "Building a document-based app using SwiftData" , open it in Xcode 16.1, and run it on an iOS 18+ simulator, you'll encounter a major issue. When you exit a document and reopen it, you'll find that the changes you just made were not saved.

iOS 18 has effectively rendered last year's WWDC 2023 sample code obsolete! Has anyone managed to successfully save data in a Document-Based App using SwiftData?


Solution

  • Definitely a bug. After you make the edits if you deactivate the app then it forces a save. So then if you close and re-open the document the changes will be there. So it is saving on app suspend but not when changes are detected. It is surprising it doesn't also force a save when the document is closed but it seems they are relying on detecting changes which is no longer working.