Created
June 24, 2022 14:58
-
-
Save saish98/1bfe75765a8f25d6d6a518c9c764bea6 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
| // | |
| // UIViewController.swift | |
| // | |
| // | |
| // Created by Saish Chachad. | |
| // | |
| import UIKit | |
| extension UIViewController { | |
| /// Alert View: Define Your number of buttons, styles and completion | |
| /// - Parameters: | |
| /// - title: Title for the alert | |
| /// - message: Message | |
| /// - actionTitles: Action button title array | |
| /// - actions: Action button callback function were you can get action of perticuler button | |
| func showSystemAlert(title: String?, | |
| message: String?, | |
| alertStyle: UIAlertController.Style = .alert, | |
| actionTitles: [String] = ["Ok"], | |
| actionStyles: [UIAlertAction.Style] = [.default], | |
| actions: [((UIAlertAction) -> Void)] = [({ _ in })]) { | |
| guard actionTitles.count == actionStyles.count, actionTitles.count == actions.count else { | |
| Logger.log("*** UIAlertController Error: ActionTitles, actionStyles and actions count must be same ***") | |
| return | |
| } | |
| let alertController = UIAlertController(title: title, message: message, preferredStyle: alertStyle) | |
| for(index, indexTitle) in actionTitles.enumerated() { | |
| let action = UIAlertAction(title: indexTitle, | |
| style: actionStyles[index], | |
| handler: actions[index]) | |
| alertController.addAction(action) | |
| } | |
| self.present(alertController, animated: true) | |
| } | |
| /// Use this func to load viewcontroller fron xib | |
| /// - Returns: Viewcontroller instance | |
| static func loadFromNib() -> Self { | |
| func instantiateFromNib<T: UIViewController>() -> T { | |
| return T.init(nibName: String(describing: T.self), bundle: nil) | |
| } | |
| return instantiateFromNib() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment