|
Hi everyone, I used same idea of iExpense project exactly but without .sheet method, The list isn't updating when I add new item from AddView.
other codes same as iExpense project.... How to fix that? project in github: https://github.com/mahoozi97/iExpense-project Thanks in advance |
|
Hi @mahoozi97! Here you can do as follows. Comments are added so I guess it is clear what has been changed. Changes to MainView:
Changes to ContentView:
Changes to AddView:
|
|
ADDITION: You might also want to add this to your save button in AddView I suppose :)
PS It is not a must to use .environmentObject to make it all work you can also pass expenses object to the views directly but for that you will need to pass object via @ObservedObject like:
|
|
Thanks @ygeras, my issue is solved. I have other question about deleted items, if I delete item and stop simulator Immediately then run again, sometimes the app recovers that deleted item. I asked here rather than share new topic. |
|
If not mistaken, UserDefaults takes some time to save data, so when you kill you app immediately after deleting an item, it might not have enough time to write data to storage. Besides UserDefaults is recommended to use for small pieces of data like settings etc. not for large set or arrays, so in reality you might not use it for real apps in this context. But for educational purposes it is more than enough. |
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
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.