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

SOLVED: How to Reset @AppStorage values

Forums > SwiftUI

Hey guys, lets say on login I am saving some values in @AppStorage, how can I clean/remove/delete all values from @AppStorage when Im logging out

2      

Since the @AppStorage and @SceneStorage property wrappers use the UserDefaults system, you can try:

if let bundleID = Bundle.main.bundleIdentifier {
    UserDefaults.standard.removePersistentDomain(forName: bundleID)
}

3      

I am n ot sure what you mean by loging in or loging out, but AppStorage is intended to persist over multiple launches of the application.

If you are refering to loging into the application and loging out of the application, then I suggest SceneStorage instead, since it will automatically delete the values when you log out (assuming you close that scene).

2      

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!

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.