Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created January 7, 2021 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/d588dfff96209cb5f359908937f2caee to your computer and use it in GitHub Desktop.
Save sturdysturge/d588dfff96209cb5f359908937f2caee to your computer and use it in GitHub Desktop.
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