SwiftUI Data & ArchitectureLesson 57Free preview
AppStorage & SceneStorage
This lesson is part of Swift · All levels
Summary
This lesson reviews the state storage of the dedicated interface in SwiftUI using @AppStorage and @SceneStorage. @AppStorage synchronizes variables globally to UserDefaults, while @SceneStorage saves the local state specific to a single window/scene (very useful for state recovery when multitasking on iPadOS and macOS).
Key points
- @AppStorage automatically reads and writes values to UserDefaults
- @SceneStorage saves a standalone window state that is automatically restored when the app reopens
- @SceneStorage is ideal for iPadOS Split View where there are two windows of the same app
- Supports primitive types such as String, Int, Double, Bool, and URL data
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.