Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
struct ContentView: View {
//Whatever scheme you entered in your project settings under URL types
let myURLScheme = "my-scheme://"
@State var text = ""
@State var openedURLs = [String]()
var fullURL: URL {
return URL(unsafeString: myURLScheme + text)
}
var body: some View {
Form {
HStack {
Text(myURLScheme)
TextField("Add text to URL", text: $text)
}
Link(destination: fullURL) {
Text("Open")
}
.onOpenURL { url in
openedURLs.append(url.absoluteString)
}
Section(header: Text("Opened URLs")) {
ForEach(0..<openedURLs.count, id: \.self) {
index in Text(openedURLs[index])
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment