SwiftUI. Add specific action in Widget

  1. General action for the entire widget. This can be achieved by adding the following modifier:
.widgetURL(<Foundation.URL?>)
  1. Action on specific views. This can be achieved by wrapping any View in Link:
Link(destination: URL.init(string: "com.foo/bar")!) {
Image(systemName: "doc.on.clipboard.fill")
.foregroundColor(.primary)
.padding(4)
}
.onOpenURL { url in
// Parse your url here to get the passed info
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store