UserDefaults
Configure cache keys for common user settings and the cache keys used by EasyApp.
EasyApp uses UserDefaults to store common user settings. For example, whether the onboarding flow has been shown, the current user's login status, the current user's selected language, etc.
Throughout the App's lifecycle, EasyApp uses the @AppStorage property wrapper to store UserDefaults values and injects them into the entire App using the .environmentObject method in the root view.
You can use the @EnvironmentObject property wrapper to access your stored UserDefaults in any view of the App.
Thanks to the @AppStorage feature, you can also modify UserDefaults values in any view, so when other views use a certain property, the page will automatically update.
Of course, you can also customize the keys that your business needs to cache. You just need to add them to EasyApp's configuration file.
enum Constants {
// MARK: - UserDefaults
enum UserDefaults {
// MARK: - isOnboarding
// This is a boolean value that is used to store whether the user has completed the onboarding process.
static let onboardingState = "onboardingState"
// MARK: - accessToken
// This is a string value that is used to store the user's access token.
static let accessToken = "accessToken"
// MARK: - selectedTab
// This is an integer value that is used to store the selected tab.
static let selectedTab = "selectedTab"
}
// MARK: - Other Keys
}Last updated on