State Restoration in SwiftUI

Learn how to use SceneStorage in SwiftUI to restore iOS app state. By Tom Elliott.

Leave a rating/review
Download materials
Save for later
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Where to Go From Here?

You can use the Download Materials button at the top or bottom of this tutorial to download the starter and final projects.

Congratulations! You've learned how easy it is to add state restoration to your app using the SceneStorage modifier and NSUserActivity.

You've seen how powerful SceneStorage can be for restoring simple data types, but also how you have a little more work to do if you plan to reuse the same View in multiple places, like tabs in a TabView, or if you need to restore complex types like model objects.

Along the way, you touched on some more advanced topics such as generics and property declaration attributes like @State and @SceneStorage.

You've also used the new NavigationStack introduced with iOS 16, and seen one way to work around problems caused when an API with stronger type safety, NavigationStack, interacts with an API that prefers simple data types, SceneStorage.

And most importantly, you've been introduced to Jamie, Agatha, Sigrid and all the most important characters from the Shadow Skye trilogy!

We hope you enjoyed this tutorial, and if you have any questions or comments, please join the forum discussion below!