SwiftUI Data Persistence w/AppStorage and SceneStorage Flashcards
What is the @SceneStorage property wrapper used for?
To store small amounts of data within the scope of individual app scene instances.
What is the @SceneStorage property wrapper ideal for?
Saving and restoring the state of a screen between app launches.
How is Scene storage declared?
Using the @SceneStorage property wrapper together with a key string value which is used internally to store the associated value.
Scene storage declaration syntax
@SceneStorage(“keyName”) var keyName: String = “”
What does the @SceneStorage property wrapper do?
Allows each individual scene within an app to have its own copy of stored data.
What is the @AppStorage property wrapper used for?
To store data that is universally available throughout the entire app.
App Storage is built on top of _____
UserDefaults
What was “UserDefaults” provided for?
- Primary use
- Secondary use
- As a way for apps to access and store default user preferences (such as language preferences or color choices).
- Can also be used to store small amounts of data need by the app in the form of key-value pairs.
App storage declaration syntax
@AppStorage(“mystore”) var mytext: String = “”
As with scene storage, the @AppStorage property wrapper requires a 1. ____ _____ to serve as a 2. _____
- String value
2. Key
By default, where will data be stored?
In the standard UserDefaults storage.
What do App Groups do?
They allow apps to share data with other apps and targets within the same group.
Where are app groups enabled and configured?
Within the Xcode project Signing and Capabilities screen.
What data types do the @AppStorage and @SceneStorage property wrappers support?
Bool, Int, Double, String, URL, and Data types.