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      

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.