-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Action.swift
55 lines (48 loc) · 1.6 KB
/
Action.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Action.swift
// Alertift
//
// Created by Suguru Kishimoto on 4/27/17.
// Copyright © 2017 Suguru Kishimoto. All rights reserved.
//
import Foundation
import UIKit
extension Alertift {
/// Action type for **Alert**, **ActionSheet**
///
/// - `default`: Default action(action title)
/// - destructive: Destructive action(action title)
/// - cancel: Cancel description(action title)
public enum Action {
typealias Handler = (UIAlertAction) -> Void
case `default`(String?)
case destructive(String?)
case cancel(String?)
init(title: String?) {
self = .default(title)
}
/// **UIAlertAction**'s title
private var title: String? {
switch self {
case .default(let title): return title
case .destructive(let title): return title
case .cancel(let title): return title
}
}
/// **UIAlertAction**'s style
private var style: UIAlertAction.Style {
switch self {
case .default( _): return .default
case .destructive( _): return .destructive
case .cancel( _): return .cancel
}
}
/// **Build UIAlertAction**
///
/// - Parameter actionHandler: Action handler for **UIAlertAction**
/// - Returns: Instance of **UIAlertAction**
func buildAlertAction(handler actionHandler: Action.Handler?) -> UIAlertAction {
return UIAlertAction(title: title, style: style, handler: actionHandler)
}
}
}