Generetic Action Sheet works for Swift 4, 4.2, 5
If you like the generic version that you can call from every ViewController and in every project, try this one:
class Alerts { static func showActionsheet(viewController: UIViewController, title: String, message: String, actions: [(String, UIAlertActionStyle)], completion: @escaping (_ index: Int) -> Void) { let alertViewController = UIAlertController(title: title, message: message, preferredStyle: .actionSheet) for (index, (title, style)) in actions.enumerated() { let alertAction = UIAlertAction(title: title, style: style) { (_) in completion(index) } alertViewController.addAction(alertAction) } viewController.present(alertViewController, animated: true, completion: nil) } }
Call like this in your ViewController.
var actions: [(String, UIAlertActionStyle)] = [] actions.append(("Action 1", UIAlertActionStyle.default)) actions.append(("Action 2", UIAlertActionStyle.destructive)) actions.append(("Action 3", UIAlertActionStyle.cancel)) //self = ViewController Alerts.showActionsheet(viewController: self, title: "D_My ActionTitle", message: "General Message in Action Sheet", actions: actions) { (index) in print("call action \(index)") /* results call action 0 call action 1 call action 2 */ }

Attention: maybe you are surprised why I added Action 1/2/3 but got results, for example, 0,1,2. In the line for (index, (title, style)) in actions.enumerated() I get the index of actions. Arrays always begin at index 0. Thus, the completion is 0.1.2.
If you want to set an enumeration, identifier, or other identifier, I would recommend passing the object in the parameters actions .