0

I am trying to allow a user to send a pdf file using the SwiftUI ShareLink. However occasionally the pdf will not be available so the function that returns the pdf will be returning an optional URL. In this case when the user presses the share button I want to show an alert. Something like this:

Button {
    if let url = render() {
        // Present the share sheet to share the pdf
    } else {
        // Present an alert
    }
} label: {
    Image(systemName: "square.and.arrow.up")
}

//func render() returns an optional url

Is there anyway to achieve this without using a representable?

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
alionthego
  • 8,508
  • 9
  • 52
  • 125
  • one thing to remember is that you don't show the `alert` or `sheet` in the `Button`. All you can do is to change a variable, initially declared as: `@Static var showAlert = false` to `showAlert = true` in the `Button`, and show the `alert` outside of the `Button` based on that condition. – workingdog support Ukraine Jan 28 '23 at 23:00

0 Answers0