100 Days of SwiftUI
2026-06-01
Project 9, part 1
Learning about (app) navigation.
Though having a course on celestial navigation might be fun 🤔
It’s not all NavigationStack!
The problem with a simple NavigationLink
SwiftUI creates the detail view at the same time it creates the main view. For a simple app with only a couple views this might be ok, but if there are a lot of complicated (dynamically generated) views it might become a problem. A lot of work is being done before it’s needed.
Handling navigation the smart way with navigationDestination()
We are “separat[ing] the destination from the value”. I’m not quite sure what that means.
- attach a value to the
NavigationLink. It can be anything, but it must beHashable - attach a
navigationDestination()modifier inside the navigation stack to let it know what to do
- you can have multiple
navigationDestination()calls depending on the type of data you are giving it - “most” of Swift’s data types conform to
Hashable - Hashing is a way to compare to complex objects easily. The hash value for each piece of data should be unique and consistent. In other words, you use hashing to make sure the large file you downloaded is what you thought you downloaded.
- if you make a struct with properties that are all
Hashableyou can add the protocol to the struct to make it conform
This is going to be a very confusing thing for me I think. Not that you need Hashable or that you wait until you need the view before you see it, but the process of navigating to a view. Can you style it? How? Nest a new View body?