UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Ultimate Portfolio App - deleteAll doesn't delete?

Forums > Articles

After calling deleteAll() and creating a new dataset, old data is still visible in the ProjectsView. At least for me! Is this expected, is the View holding on to some cached data?

6      

Same question here. Hitting "add" several time should to my understanding delete all projects/ items and create 5 new projects. However old data keeps staying.

5      

Well I really don't know what went wrong here, but editing the Add Data button in HomeView and rebuilding made it work as expected. Weird.

5      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Could you kindly let me know what you edited exactly on the Button?

5      

I tested to add a new button doing only the delete, and it worked fine. Then I undid my edit, back to the original, and it still worked. I really can't figure out what happened. 🤷

5      

Looks like we need a call to dataController.save() in HomeView after the call to dataController.deleteAll(). Look at this tweet.

https://twitter.com/MrGLWatson/status/1320448229914353666

5      

Well done @TwoFortyTwoApps

Here

Button("Add Data") {
    dataController.deleteAll()
    dataController.save()
    try? dataController.createSampleData()
}

5      

This is still not updating until I restart the app even after doing

Button("Add Data") {
    dataController.deleteAll()
    dataController.save()
    try? dataController.createSampleData()
}

5      

5      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.