Introducing @AppStorage in SwiftUI

Mark van Wijnen
The Startup
Published in
7 min readSep 26, 2020

--

Everything you need to know about @AppStorage

What is an App?

Before we dive into @AppStorage we need to talk about what an App is first. An app is short for application, which is a software program that runs on your device, but I bet you already knew that. What you may not know is that Apple added the App-protocol to SwiftUI, which is first talked about in the App essentials in SwiftUI talk from WWDC 2020.

You have one App, that can have one or multiple Scenes that consist of one or multiple Views.

Every App has its own @AppStorage which can be accessed by all the Views in any Scene. This differs from the @SceneStorage property wrapper which has a unique storage for each of the Scenes. A View within a Scene can only access the data stored in the @SceneStorage of its own Scene and has no way of accessing the data of the @SceneStorage of another Scene. However, all Views, no matter the scenes they belong to, have access to the same data in @AppStorage.

This is how Apps, Scenes, and Views relate to one another

What is @AppStorage?

When we build our app in SwiftUI most of the data we use will be stored in the memory of our device through types as String and Integer. This doesn’t change when we use…

--

--

The Startup
The Startup

Published in The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

Mark van Wijnen
Mark van Wijnen

Written by Mark van Wijnen

macOS/iPadOS/iOS/watchOS/visionOS developer and SwiftUI enthousiast. “Stay Hungry, Stay Foolish!” — Steve Jobs

Responses (2)