Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Last active June 26, 2020 23:27
Show Gist options
  • Save sturdysturge/6fb56483b479c29e7a76b0c0589dba87 to your computer and use it in GitHub Desktop.
Save sturdysturge/6fb56483b479c29e7a76b0c0589dba87 to your computer and use it in GitHub Desktop.
LinkStyleView
struct LinkStyleView: View {
let urlString = "https://medium.com/better-programming/the-complete-swiftui-documentation-youve-been-waiting-for-fdfe7241add9"
var body: some View {
Group {
if URL(string: urlString) != nil {
//The old way to create a Link-style Button
Button("Read more") {
if let url = URL(string: urlString) {
UIApplication.shared.open(url, options: [:], completionHandler: {_ in })
}
}
}
else {
EmptyView()
.onAppear { assertionFailure("URL was nil") }
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment