This is an archived post from my old WordPress blog. Some code examples may reference older versions of Swift or SwiftUI.
SwiftUI makes opening a URL with your default web browser super easy with the Link view. All you need to do is give it a title and a destination URL. Let us take a look at the example below.
import SwiftUI
struct ContentView: View {
var body: some View {
Link("Swift Tom!", destination: URL(string: "https://www.swifttom.com/")!)
}
}


As you can see in our example we are added a title of βSwift Tom!β and our destination URL swifttom.com. If we go and run this code in our simulator we will see our Link button that when it is tapped will bring us to my swifttom.com webpage.
Hope you enjoyed this quick look at how we can use Link views to our SwiftUI project.
For more on how to use Link views we can check out Appleβs Documentation here.
πππ Happy Coding! πππ