Skip to content

Instantly share code, notes, and snippets.

@megabitsenmzq
Last active August 25, 2023 10:04
Show Gist options
  • Save megabitsenmzq/cda51143450fb6a56614faedb738132f to your computer and use it in GitHub Desktop.
Save megabitsenmzq/cda51143450fb6a56614faedb738132f to your computer and use it in GitHub Desktop.
Show UIKit alert in SwiftUI.
// SwiftUI alert has so many problems. Use UIKit instead.
import UIKit
struct UIAlertControllerWrapper {
static func present(alert: UIAlertController) {
if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene, let root = scene.windows.first?.rootViewController {
var nextViewController = root
while nextViewController.presentedViewController != nil {
nextViewController = nextViewController.presentedViewController!
}
nextViewController.present(alert, animated: true, completion: nil)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment