struct Result
The closure to run for the given URL. The closure takes a URL as input, and returns a Open
that indicates the outcome of the action.
Availability 有効性
Technology
init(handler: @escaping (URL
) -> OpenURLAction
.Result
)
handler
The closure to run for the given URL. The closure takes a URL as input, and returns a Open
that indicates the outcome of the action.
Use this initializer to create a custom action for opening URLs. Provide a handler that takes a URL and returns an Open
. Place your handler in the environment using the environment(_:
view modifier:
Text("Visit [Example Company](https://www.example.com) for details.")
.environment(\.openURL, OpenURLAction { url in
handleURL(url) // Define this method to take appropriate action.
return .handled
})
Any views that read the action from the environment, including the built-in Link
view and Text
views with markdown links, or links in attributed strings, use your action.
SwiftUI translates the value that your custom action’s handler returns into an appropriate Boolean result for the action call. For example, a view that uses the action declared above receives true
when calling the action, because the handler always returns handled
.
struct Result