Skip to content

Instantly share code, notes, and snippets.

@arpitjain03
Created September 27, 2017 12:43
Show Gist options
  • Save arpitjain03/92b56eb43932135bd9fbc58aff84c86b to your computer and use it in GitHub Desktop.
Save arpitjain03/92b56eb43932135bd9fbc58aff84c86b to your computer and use it in GitHub Desktop.
// 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