Relative Content

Tag Archive for swiftuiswift-data

How can document settings/metadata be saved in SwiftData/SwiftUI?

Background: I had an old CoreData, document-based app where it was expected each document would apply to a specific year, in a specific state/province. It made the most sense to save the year and location on a per-document basis, outside of the CoreData model. I managed use the document’s metadata dictionary, accessed via the NSPersistentStore, as described in this question: How can document-based settings be stored?

How to know when a SwiftUI View redraw has completed

My MacOS app uses SwiftData and SwiftUI to store and display recipes. When I add a new recipe to my SwiftData model, my List of recipes updates. At this point I want to programatically scroll to the new recipe by changing a State variable (selectedRecipe) and using the .onChange modifier to action a scrollTo() command. But the scroll never happens, I believe because the List has not yet been updated.