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 {


}

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)
    }
}

call that method as to follow.
                triggerAlert(msg: "message")

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift