Member-only story

Navigation in SwiftUI (Update to iOS 18)

Nicola De Filippo
4 min readSep 19, 2024

NavigationBar

Start from the code of the previous post (https://nicoladefilippo.com/list-in-swiftui/):

struct Vehicle: Identifiable {
var id = UUID()
var name: String
var image: String
}

struct ContentView: View {
@State var vehicles = [Vehicle(name: "car", image: "car"),
Vehicle(name: "bus", image: "bus"),
Vehicle(name: "tram", image: "tram"),
Vehicle(name: "bicycle", image: "bicycle")]

var body: some View {
List {
ForEach(vehicles) { vehicle in
RowView(vehicle: vehicle)
}
.onDelete { (indexSet) in
self.vehicles.remove(atOffsets: indexSet)
}
}
}
}

struct RowView: View {
var vehicle: Vehicle
var body: some View {
HStack {
Image(systemName: vehicle.image)
.resizable()
.frame(width: 60, height: 60)
Text(vehicle.name)
}
}
}

We want to tap on one row and skip to a new view.

The first step is add a NavigationStack:

var body: some View {
NavigationStack {
List {
ForEach(vehicles) { vehicle in
NavigationLink { EmptyView()
} label:{

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Nicola De Filippo
Nicola De Filippo

Written by Nicola De Filippo

Software Engineer and Entrepreneur

Responses (2)

Write a response

NavigationView is legacy and is no longer supported. Also, I think using NavigationLink is also an older and now outdated method of navigation in SwiftUI. NavigationPath allows for much more control and is the direction apple seems to be going

Hi Nicola, consider to apply navigation only with navigation stack.
The navigation view is deprecated, maybe the title should be change bit more