This is an archived post from my old WordPress blog. Some code examples may reference older versions of Swift or SwiftUI.

How to Use Link to Open Webpages in SwiftUI

December 11, 2020 By Thomas Prezioso Jr 1 min read

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! πŸ”—πŸ”—πŸ”—


Share this post
Post on X Share on LinkedIn

Back to top

Β© 2025 Thomas Prezioso Jr. All rights reserved.

Built with Swift using Ignite