4

I know with AttributedString, I can link to an external website using something like:

Text("To learn more about AttributedString visit [this page](https://developer.apple.com/documentation/foundation/attributedstring/)")

Can I use this to go from ViewA to ViewB within the same app, kind of like this example in Twitter?

Twitter

1

1 Answer 1

7

You can store an OpenURLAction in the environment to override how subviews like Text and Link open URLs.

This example is from the documentation:

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
    })

You may want to apply the environment modifier at a high level of your view hierarchy (near your root view) rather than directly on each Text view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.