11import UIKit
22
3+ /// A controller that presents an alert with a title, message, and up to two action buttons.
4+ ///
5+ /// - Example:
6+ /// ```swift
7+ /// let alert = UKAlertController(
8+ /// model: .init { alertVM in
9+ /// alertVM.title = "My Alert"
10+ /// alertVM.message = "This is an alert."
11+ /// alertVM.primaryButton = .init { buttonVM in
12+ /// buttonVM.title = "OK"
13+ /// buttonVM.color = .primary
14+ /// buttonVM.style = .filled
15+ /// }
16+ /// alertVM.secondaryButton = .init { buttonVM in
17+ /// buttonVM.title = "Cancel"
18+ /// buttonVM.style = .light
19+ /// }
20+ /// }, primaryAction: {
21+ /// NSLog("Primary button tapped")
22+ /// }, secondaryAction: {
23+ /// NSLog("Secondary button tapped")
24+ /// }
25+ /// )
26+ ///
27+ /// vc.present(alert, animated: true)
28+ /// ```
329public class UKAlertController : UKCenterModalController {
30+ // MARK: - Properties
31+
32+ /// The model that defines the appearance of the alert.
433 public let alertVM : AlertVM
534
35+ /// The primary action to be executed when the primary button is tapped.
36+ public var primaryAction : ( ( ) -> Void ) ?
37+ /// The secondary action to be executed when the secondary button is tapped.
38+ public var secondaryAction : ( ( ) -> Void ) ?
39+
40+ // MARK: - Subviews
41+
42+ /// The label used to display the title of the alert.
643 public let titleLabel = UILabel ( )
44+ /// The label used to display the subtitle or message of the alert.
745 public let subtitleLabel = UILabel ( )
46+ /// The button representing the primary action in the alert.
847 public let primaryButton = UKButton ( )
48+ /// The button representing the secondary action in the alert.
949 public let secondaryButton = UKButton ( )
50+ /// A stack view that arranges the primary and secondary buttons.
1051 public let buttonsStackView = UIStackView ( )
1152
12- public var primaryAction : ( ( ) -> Void ) ?
13- public var secondaryAction : ( ( ) -> Void ) ?
53+ // MARK: - Initialization
1454
55+ /// Initializer.
56+ ///
57+ /// - Parameters:
58+ /// - model: The `AlertVM` model that defines the appearance and behavior of the alert.
59+ /// - primaryAction: An optional closure executed when the primary button is tapped.
60+ /// - secondaryAction: An optional closure executed when the secondary button is tapped.
1561 public init (
1662 model: AlertVM ,
1763 primaryAction: ( ( ) -> Void ) ? = nil ,
@@ -29,6 +75,8 @@ public class UKAlertController: UKCenterModalController {
2975 fatalError ( " init(coder:) has not been implemented " )
3076 }
3177
78+ // MARK: - Setup
79+
3280 public override func setup( ) {
3381 if self . alertVM. title. isNotNilAndEmpty,
3482 self . alertVM. message. isNotNilAndEmpty {
@@ -65,6 +113,8 @@ public class UKAlertController: UKCenterModalController {
65113 super. setup ( )
66114 }
67115
116+ // MARK: - Style
117+
68118 public override func style( ) {
69119 super. style ( )
70120
@@ -80,6 +130,8 @@ public class UKAlertController: UKCenterModalController {
80130 }
81131 }
82132
133+ // MARK: - Layout
134+
83135 public override func updateViewConstraints( ) {
84136 super. updateViewConstraints ( )
85137
@@ -116,6 +168,8 @@ public class UKAlertController: UKCenterModalController {
116168 }
117169}
118170
171+ // MARK: - Style Helpers
172+
119173extension UKAlertController {
120174 fileprivate enum Style {
121175 static func titleLabel( _ label: UILabel , text: String ? ) {
0 commit comments