func callAsFunction (URL)
Opens a URL, following system conventions.
Availability 有効性
Technology
url
The URL to open.
completion
A closure the method calls after determining if it can open the URL, but possibly before fully opening the URL. The closure takes a Boolean value that indicates whether the method can open the URL.
Don’t call this method directly. SwiftUI calls it when you call the Open
structure that you get from the Environment
, using a URL and a completion handler as arguments:
struct OpenURLExample: View {
private var openURL (\.openURL)
var body: some View {
Button {
if let url = URL(string: "https://www.example.com") {
// Implicitly calls openURL.callAsFunction(url) { ... }
openURL(url) { accepted in
print(accepted ? "Success" : "Failure")
}
}
} label: {
Label("Get Help", systemImage: "person.fill.questionmark")
}
}
}
For information about how Swift uses the call
method to simplify call site syntax, see Methods with Special Names in The Swift Programming Language.
func callAsFunction (URL)