Instance Method インスタンスメソッド

callAsFunction(_:)

Opens a URL, following system conventions.

Declaration 宣言

func callAsFunction(_ url: URL)

Parameters パラメータ

url

The URL to open.

Discussion 議論

Don’t call this method directly. SwiftUI calls it when you call the OpenURLAction structure that you get from the Environment, using a URL as an argument:


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


    var body: some View {
        Button {
            if let url = URL(string: "https://www.example.com") {
                openURL(url) // Implicitly calls openURL.callAsFunction(url)
            }
        } label: {
            Label("Get Help", systemImage: "person.fill.questionmark")
        }
    }
}

For information about how Swift uses the callAsFunction() method to simplify call site syntax, see Methods with Special Names in The Swift Programming Language.

See Also 参照

Calling the Action