Created
September 27, 2017 12:43
-
-
Save arpitjain03/92b56eb43932135bd9fbc58aff84c86b 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
// CustomAlert.swift | |
// CustomAlert | |
// Created by Arpit Jain on 27/09/17. | |
// Copyright © 2017 Arpit Jain. All rights reserved. | |
// | |
import UIKit | |
/// This is a class created for handling Alerts in Project | |
class AlertClass: NSObject { | |
/** | |
Call this function for showing alert with OK and Cancel button in your View Controller class. | |
- Parameters: | |
- VC : View Controller over which the function is called. You can use self, or provide view controller name. | |
- message: Pass your alert message in String. | |
- okClickHandler: This will give you call back inside block when OK button is clicked | |
### Usage Example: ### | |
```` | |
AlertClass().showAlert(self, andMessage: "This is custom alert") { (okClick) in | |
} | |
```` | |
*/ | |
func showAlert(_ VC : UIViewController, andMessage message: String , okClickHandler :@escaping(UIAlertAction) -> Void){ | |
DispatchQueue.main.async { | |
let alert = UIAlertController(title: "APPLICATION_NAME", message: message , preferredStyle: UIAlertControllerStyle.alert) | |
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: okClickHandler)) | |
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil)) | |
VC.present(alert, animated: true, completion: nil) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment