Global alertView iOS Swift
AlertView is used more times in iOS apps.Because we have notified the errors and information using alertView.First, we have to create Utility class then implement the alertView inside the class and call in the entire app in a single Line.Implementation as to follow.
Code:
class Utils: NSObject {
class Utils: NSObject {
}
func triggerAlert(msg:NSString) {
if let topController = UIApplication.topViewController() {
let alert = UIAlertController(title: "AppTitle" as String , message: msg as String, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler:nil))
topController.present(alert, animated: true, completion: nil)
}
}
-
triggerAlert(msg: "message")
Comments
Post a Comment