-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActionSheetManager.swift
32 lines (20 loc) · 1.09 KB
/
ActionSheetManager.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import UIKit
// MARK: - This class is used to make native ActionSheet as per requirements -
class ActionSheetManager {
class func actionSheetDynamic(title: String = "Alert", message: String = "Choose Options", buttonTitlesArray: [String], successCallBack: @escaping (String) -> Void, errorCallBack: @escaping () -> Void) {
let actionSheet = UIAlertController(title: title, message: message, preferredStyle: .actionSheet)
for item in buttonTitlesArray {
let actionSheetButton = UIAlertAction(title: item, style: .default) { (alert) in
successCallBack(item)
}
actionSheet.addAction(actionSheetButton)
}
let cancelButton = UIAlertAction(title: CANCEL, style: .cancel) { (alert) in
errorCallBack()
}
actionSheet.addAction(cancelButton)
if let topViewController = UIApplication.topViewController() {
topViewController.present(actionSheet, animated: true, completion: nil)
}
}
}