Member-only story

Advanced Deep Linking In SwiftUI

True deep linking is difficult and most of us don’t bother. Here are the techniques I developed for Navigator that make it much, much easier.

Michael Long
12 min readFeb 3, 2025

We’ve all seen the classic example of using SwiftUI's new openURL modifier to enable “deep” linking in our applications, usually by presenting a view in a sheet.

@State var showSheet = false
var body: some View {
VStack {
Button("Present Sheet") {
if let url = URL(string: "myapp://showSheet") {
openURL(url)
}
}
}
.onOpenURL { url in
if url.host == "showSheet" {
showSheet = true
}
}
.sheet(isPresented: $showSheet) {
SheetView()
}
}

Define the presentation “show” variable, use openURL to parse the URL, and if it matches, present the sheet.

NavigationPath

What could be easier, right? But what if we don’t want to present the view but add it to our current navigation path instead?

@State var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
VStack {
Button("Push Detail") {
if let url = URL(string: "myapp://showDetail") {…

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (2)