WWDC 2025 deal: 30% off our Swift and SwiftUI books! Learn more ...WWDC 2025 deal:30% off our Swift and SwiftUI books >>
Quick Tip Icon
Quick Tip

Set custom actions for links in Text views

Since iOS 15 and macOS 12 SwiftUI Text views can contain interactive links created with Markdown or AttributedString.

To customize actions of such links we can use openURL environment value.

struct ContentView: View {
    var body: some View {
        Text("Visit our [website](https://example.com)")
            .environment(\.openURL, OpenURLAction { url in
                handleURL(url)
                return .handled
            })
    }
    
    func handleURL(_ url: URL) {
        // handle URL here
    }
}
Swift Gems by Natalia Panferova book coverSwift Gems by Natalia Panferova book cover

WWDC 2025 offer: 30% off!$35$25

100+ tips to take your Swift code to the next level

Swift Gemsby Natalia Panferova

  • Advanced Swift techniques for experienced developers bypassing basic tutorials
  • Curated, actionable tips ready for immediate integration into any Swift project
  • Strategies to improve code quality, structure, and performance across all platforms
WWDC 2025 offer: 30% off!

100+ tips to take your Swift code to the next level

Swift Gems by Natalia Panferova book coverSwift Gems by Natalia Panferova book cover

Swift Gems

by Natalia Panferova

$35$25