Understating why SwiftUI navigation is a challenge
To answer that question, we need to understand how navigation works intuitively. The user taps on a button, link, or some other event that may occur. Then, the app responds to that event and transitions the view to another screen.
In a sense, we understand this sounds like an event-driven paradigm. When we discuss the differences between SwiftUI and UIKit, we actually discuss the differences between declarative and imperative programming.
Imperative UI, such as UIKit, is also event-driven, while declarative UI, such as SwiftUI, represents the current state. As a result, we can understand why navigation can be seen as simpler in UIKit and may feel more natural there.
Many developers struggle with SwiftUI navigation. They wrap a SwiftUI view inside UIHostingController
and use the UIKit navigation system. That’s a fair solution for achieving some advanced navigation techniques that are hard to do in SwiftUI. However, we...