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: "")!)

As you can see in our example we are added a title of “Swift Tom!” and our destination URL 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 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! πŸ”—πŸ”—πŸ”—

Leave a Reply