title: How to present an Alert in SwiftUI with no buttons
body: <p>I have a situation where I would like to recreate previous <code>UIKit</code> logic by displaying an <code>Alert</code> during a long running operation that the user cannot interact with.</p>
  <p>Previously in UIKit, it would be this simple:</p>
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
      override func viewDidAppear(_ animated: Bool) {
          super.viewDidAppear(animated)
          let alertController = UIAlertController(title: &quot;Loading&quot;,
                                                  message: nil,
                                                  preferredStyle: .alert)
          present(alertController, animated: true, completion: nil)
      }
  }
  </code></pre>
  <p>And it looks like this:</p>
  <p><a href="https://i.stack.imgur.com/Wjvwn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wjvwn.png" alt="enter image description here" /></a></p>
  <p>A simple <code>SwiftUI</code> based version can be created as such:</p>
  <pre><code>import SwiftUI
  
  struct ContentView: View {
      @State private var isLoading = true
      
      var body: some View {
          Text(&quot;Hello&quot;)
              .modifier(LoadingAlert(isPresented: $isLoading))
      }
  }
  
  struct LoadingAlert: ViewModifier {
      @Binding var isPresented: Bool
  
      func body(content: Content) -&gt; some View {
          content
              .alert(isPresented: $isPresented) {
                  Alert(title: Text(NSLocalizedString(&quot;Loading&quot;, comment: &quot;&quot;)),
                        dismissButton: .none)
              }
      }
  }
  </code></pre>
  <p>Whether I use <code>nil</code> or <code>.none</code> as the <code>dismissButton</code> argument, or completely omit the line, it will use a default <code>OK</code> button, and produce this:</p>
  <p><a href="https://i.stack.imgur.com/GWoi8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GWoi8.png" alt="enter image description here" /></a></p>
  <p>I did modify the <code>Alert</code> arguments, sending in a button with an empty <code>title</code>, but this is the result, which is not as clean as I would like:</p>
  <pre><code>dismissButton: .default(Text(&quot;&quot;)))
  </code></pre>
  <p><a href="https://i.stack.imgur.com/puHO1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/puHO1.png" alt="enter image description here" /></a></p>
  <p>Based on what I have seen, it does not appear that the Alert in SwiftUI supports what I want, based upon inspecting its initializers.</p>
  <pre><code>/// Creates an alert with one button.
  public init(title: Text, message: Text? = nil, dismissButton: Alert.Button? = nil)
  
  /// Creates an alert with two buttons.
  ///
  /// - Note: the system determines the visual ordering of the buttons.
  public init(title: Text, message: Text? = nil, primaryButton: Alert.Button, secondaryButton: Alert.Button)
  </code></pre>
  <p>For this project, the goal is to fully utilize SwiftUI, but it appears this is a scenario where we cannot get the desired result.</p>
  <p>My take is either we will have to pull in a UIKit based <code>AlertController</code>, or use a different effect to indicate status. However, I'd love to be wrong here.</p>