NEW BOOK! The SwiftUI Way: A field guide to SwiftUI patterns and anti-patterns. Learn more ...NEW BOOK! The SwiftUI Way:Avoid common SwiftUI pitfalls. Learn more...
Quick Tip

Clearing UserDefaults during macOS app development

While building and testing a macOS app locally, values stored in UserDefaults remain between launches. This includes data stored using the UserDefaults APIs directly or data persisted via the SwiftUI's @AppStorage property wrapper. But it's often useful to clear saved values to test onboarding, restore default settings, and reproduce a fresh app state.

We can quickly clear this saved data directly from Terminal using the defaults command.

To remove all values stored in an app's default domain, run:

defaults delete com.example.MyApp

Replace com.example.MyApp with your app’s bundle identifier.

To remove a specific value, provide the key:

defaults delete com.example.MyApp hasCompletedOnboarding

This can be useful when testing a specific flow without clearing everything.

If the app stores values in a custom suite, use the suite name in place of the bundle identifier.

To remove all stored values from the suite, run the following command replacing group.com.example.shared with your suite name:

defaults delete group.com.example.shared

To remove a specific value from the suite, provide the key after the suite name:

defaults delete group.com.example.shared hasCompletedOnboarding


The SwiftUI Way by Natalia Panferova book coverThe SwiftUI Way by Natalia Panferova book cover

Work with SwiftUI. Not against it.$35

A field guide to SwiftUI patterns and anti-patterns

The SwiftUI Wayby Natalia Panferova

  • Avoid common SwiftUI pitfalls
  • Build deeper intuition for the framework
  • Gain insights from a former SwiftUI Engineer at Apple

Work with SwiftUI. Not against it.

A field guide to SwiftUI patterns and anti-patterns

The SwiftUI Way by Natalia Panferova book coverThe SwiftUI Way by Natalia Panferova book cover

The SwiftUI Way

by Natalia Panferova

$35