Post

Replies

Boosts

Views

Activity

Reply to Connecting SwiftUI app to CoreData
I think it’s is quite the opposite. The new @StateObject property wrapper will instantiate just before the view is created and will live until that view is destroyed. Based on this view being the main view for the app, I would expect the data and the view to live until the app closes. Adding core data just ensures the data is persisted, but we still need to fetch the data before the view is created. But more importantly, we need to save the data more carefully so that the app will fetch the fresher data changes whenever the view is about to appear. Therefore, if this main view gets replaced during the app’s life cycle, I would expect the data would go away, any unsaved changes would be lost. That is why we should now use the onChange event to save data changes when they happen. That way, when the view is recreated, we can load the persisted data and not lose our previously made changes.
Jun ’20
Reply to Connecting SwiftUI app to CoreData
There is a tutorial from RayWenderlich.com on how to use CoreData with SwiftUI. Also, there are videos and written tutorials on HackingWithSwift.com It appears you are missing some of the fundamentals. I am not allowed to include URLs. Just Google SwiftUI CoreData to find them quickly.
Jun ’20