Answer: Inside your App struct, implement the .onOpenURL view modifier on ContentView:

Here, we have a @State property, which is synced with ContentView using @Binding (I go in depth about that here).

This is what ContentView looks like:

It displays a Text that shows the link (I used a URL scheme, called helloworld) that the app was launched from. And if the app was not launched from a link, it displays the placeholder.

Left: when launched from a link. Right: when launched directly from the home screen.

Because a @State property updates automatically, .onOpenURL is able to replace both of the functions from SceneDelegate — in SwiftUI, you don’t need a separate function for loading the url on first launch, and another one for loading the url after coming back from the background.

You can get more information about .onOpenUrl here.

Answer: There’s a lot of ways to do this, but the easiest is to use a notification publisher. Here’s what ContentView will look like:

Source from Koraktor’s great Stack Overflow answer


Basically, we’re combining Foundation’s Notification Center with Combine’s Publisher (Foundation and Combine are frameworks). You can check this out for more information on Notification Publishers.



WWDC21 Scholar. I like to read manga and write about Swift. Check out my app, Find — look for text in real life, with outrageous speed.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store