Skip to content

Instantly share code, notes, and snippets.

@alexbosworth
Created November 19, 2015 04:48
Show Gist options
  • Save alexbosworth/1a75f047048bc5d602b9 to your computer and use it in GitHub Desktop.
Save alexbosworth/1a75f047048bc5d602b9 to your computer and use it in GitHub Desktop.
import UIKit
/** Alert controller that can be presented in any context and it will appear on top
*/
class GlobalAlertController: UIAlertController {
// MARK: - Properties (Private Mutable)
/** Window to present alert controller in
*/
private lazy var _window: UIWindow = {
let window = UIWindow(frame: UIScreen.mainScreen().bounds)
window.backgroundColor = .clearColor()
window.rootViewController = UIViewController()
return window
}()
// MARK: - Visibility Methods
/** Show the alert controller
*/
func present(animated: Bool = true, completion: CompletionClosure? = nil) {
guard let rootVC = _window.rootViewController else { return Errors.report(.ExpectedProperty) }
_window.makeKeyAndVisible()
rootVC.presentViewController(self, animated: animated, completion: completion)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment