How do I add Navigation to my swiftui app?
Asked on 08/09/2024
1 search
To add navigation to your SwiftUI app, you can use the NavigationStack
and NavigationLink
components. Here's a basic example to get you started:
- Create a NavigationStack: This is the container for your navigable views.
- Use NavigationLink: This is used to navigate to a new view when a user interacts with a UI element.
Here's a simple example:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationStack {
List {
NavigationLink("Go to Detail View", destination: DetailView())
}
.navigationTitle("Home")
}
}
}
struct DetailView: View {
var body: some View {
Text("This is the detail view")
.navigationTitle("Detail")
}
}
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
In this example:
NavigationStack
is used to wrap the content that will be navigable.NavigationLink
is used to create a link to theDetailView
.navigationTitle
sets the title for the navigation bar.
For more advanced navigation features, such as split views or customizable multi-column tables, you can refer to the session SwiftUI essentials which covers these topics in detail.
Relevant Sessions
These sessions provide a comprehensive overview of the new features and best practices for using navigation in SwiftUI.

Elevate your tab and sidebar experience in iPadOS
iPadOS 18 introduces a new navigation system that gives people the flexibility to choose between using a tab bar or sidebar. The newly redesigned tab bar provides more space for content and other functionality. Learn how to use SwiftUI and UIKit to enable customization features – like adding, removing and reordering tabs – to enable a more personal touch in your app.

Enhance your UI animations and transitions
Explore how to adopt the zoom transition in navigation and presentations to increase the sense of continuity in your app, and learn how to animate UIKit views with SwiftUI animations to make it easier to build animations that feel continuous.

SwiftUI essentials
Join us on a tour of SwiftUI, Apple’s declarative user interface framework. Learn essential concepts for building apps in SwiftUI, like views, state variables, and layout. Discover the breadth of APIs for building fully featured experiences and crafting unique custom components. Whether you’re brand new to SwiftUI or an experienced developer, you’ll learn how to take advantage of what SwiftUI has to offer when building great apps.