NavigationLink
Part of the Introduction to SwiftUI section of Coddy's Swift journey. Lesson 35 of 50.
A NavigationLink is a row or button that pushes a new screen when tapped. It needs a title and a destination view:
NavigationStack {
List {
NavigationLink("Pancakes") {
Text("Mix flour, eggs and milk")
.navigationTitle("Pancakes")
}
}
.navigationTitle("Recipes")
}Tapping the row slides in the destination, which sets its own title. The bar then shows a back button named after the previous screen, Recipes, that returns to the list. Inside a List, a link row shows a chevron on the right.
The destination can be any view, including your own view structs.
Challenge
EasyTurn the Pancakes row into a NavigationLink. Its destination is a text Mix flour, eggs and milk with the identifier steps, and the destination's title is Pancakes.
Try it yourself
import SwiftUI
@main
struct CoddyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Introduction to SwiftUI
Practice on your own: Swift playground