DEV Community

Thomas Prezioso Jr.
Thomas Prezioso Jr.

Posted on

How to Use Link to Open Webpages in 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! 🔗🔗🔗

Top comments (0)