DEV Community

Thomas Prezioso Jr.
Thomas Prezioso Jr.

Posted on

2 1

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

AWS Q Developer image

Your AI Code Assistant

Implement features, document your code, or refactor your projects.
Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay