@@ -70,11 +70,11 @@ public extension UIAlertController {
7070 title: String ,
7171 style: UIAlertAction . Style = . default,
7272 handler: ( ( UIAlertAction ) -> Void ) ? = nil ) -> UIAlertAction {
73-
74- let action = UIAlertAction ( title: title, style: style, handler: handler)
75- addAction ( action)
76- return action
77- }
73+
74+ let action = UIAlertAction ( title: title, style: style, handler: handler)
75+ addAction ( action)
76+ return action
77+ }
7878
7979 /**
8080 SparrowKit: Add Text Field to Alert Controller.
@@ -89,15 +89,15 @@ public extension UIAlertController {
8989 placeholder: String ? = nil ,
9090 editingChangedTarget: Any ? ,
9191 editingChangedSelector: Selector ? ) {
92-
93- addTextField { textField in
94- textField. text = text
95- textField. placeholder = placeholder
96- if let target = editingChangedTarget, let selector = editingChangedSelector {
97- textField. addTarget ( target, action: selector, for: . editingChanged)
92+
93+ addTextField { textField in
94+ textField. text = text
95+ textField. placeholder = placeholder
96+ if let target = editingChangedTarget, let selector = editingChangedSelector {
97+ textField. addTarget ( target, action: selector, for: . editingChanged)
98+ }
9899 }
99100 }
100- }
101101
102102 /**
103103 SparrowKit: Add Text Field to Alert Controller.
@@ -111,14 +111,29 @@ public extension UIAlertController {
111111 text: String ? = nil ,
112112 placeholder: String ? = nil ,
113113 action: UIAction ? ) {
114-
115- addTextField { textField in
116- textField. text = text
117- textField . placeholder = placeholder
118- if let action = action {
119- textField . addAction ( action , for : . editingChanged )
114+ addTextField { textField in
115+ textField. text = text
116+ textField. placeholder = placeholder
117+ if let action = action {
118+ textField . addAction ( action, for : . editingChanged )
119+ }
120120 }
121121 }
122+
123+ static func confirm( title: String , description: String , actionTitle: String , cancelTitle: String , desctructive: Bool , action: @escaping ( ) -> Void , sourceView: UIView , on controller: UIViewController ) {
124+ let alertController = UIAlertController . init ( title: title, message: description, preferredStyle: . actionSheet)
125+ alertController. popoverPresentationController? . sourceView = sourceView
126+ alertController. addAction ( title: actionTitle, style: desctructive ? . destructive : . default) { [ ] _ in
127+ action ( )
128+ }
129+ alertController. addAction ( title: cancelTitle, style: . cancel, handler: nil )
130+ controller. present ( alertController)
131+ }
132+
133+ static func confirmDouble( title: String , description: String , actionTitle: String , cancelTitle: String , desctructive: Bool , action: @escaping ( ) -> Void , sourceView: UIView , on controller: UIViewController ) {
134+ confirm ( title: title, description: description, actionTitle: actionTitle, cancelTitle: cancelTitle, desctructive: desctructive, action: {
135+ confirm ( title: title, description: description, actionTitle: actionTitle, cancelTitle: cancelTitle, desctructive: desctructive, action: action, sourceView: sourceView, on: controller)
136+ } , sourceView: sourceView, on: controller)
122137 }
123138}
124139#endif
0 commit comments