Last active
August 25, 2023 10:04
-
-
Save megabitsenmzq/cda51143450fb6a56614faedb738132f to your computer and use it in GitHub Desktop.
Show UIKit alert in SwiftUI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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