Created
November 19, 2015 04:48
-
-
Save alexbosworth/1a75f047048bc5d602b9 to your computer and use it in GitHub Desktop.
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
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