Book Image

An iOS Developer's Guide to SwiftUI

By : Michele Fadda
Book Image

An iOS Developer's Guide to SwiftUI

By: Michele Fadda

Overview of this book

– SwiftUI transforms Apple Platform app development with intuitive Swift code for seamless UI design. – Explore SwiftUI's declarative programming: define what the app should look like and do, while the OS handles the heavy lifting. – Hands-on approach covers SwiftUI fundamentals and often-omitted parts in introductory guides. – Progress from creating views and modifiers to intricate, responsive UIs and advanced techniques for complex apps. – Focus on new features in asynchronous programming and architecture patterns for efficient, modern app design. – Learn UIKit and SwiftUI integration, plus how to run tests for SwiftUI applications. – Gain confidence to harness SwiftUI's full potential for building professional-grade apps across Apple devices.
Table of Contents (25 chapters)
Free Chapter
1
Part 1: Simple Views
5
Part 2: Scrollable Views
8
Part 3: SwiftUI Navigation
11
Part 4: Graphics and Animation
14
Part 5: App Architecture
17
Part 6: Beyond Basics

Saving and loading the navigation stack

NavigationPath, besides .append() and .removeLast(), provides .count and .isEmpty properties, which you could use in order to control the stack programmatically. Basically, you can delete and create whatever you want on the stack, in however many levels as you please, and you can do it all programmatically.

So, you could come up with your own solution to save the stack programmatically or manipulate it in any way you want. One possible suggestion could be using a state machine pattern if you have a really complex navigation structure in mind.

But in order to make things even easier, NavigationPath has a .codable property, which allows you to convert to and from JSON format. You could send the path to a server, deep link a view of your app from a web service, and so on.

One of the many applications is storing the path so that when the app is suspended or terminated, it is restored when the app is started, so that the app has a persistent...