Home > AI > IOS > SwiftUI >

open URL

Method 1:

struct ContentView: View {

    var body: some View {
        Link("Visit Apple",
              destination: URL(string: "https://www.apple.com")!)
            .font(.title)
            .foregroundColor(.red)
    }
}

Method 2:

struct ContentView: View {
    @Environment(\.openURL) var openURL

    var body: some View {
        Button("Visit Apple") {
            openURL(URL(string: "https://www.apple.com")!)
        }
    }
}

Leave a Reply