forked from pointfreeco/swift-composable-architecture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlertStateUIKit.swift
More file actions
58 lines (56 loc) · 1.68 KB
/
AlertStateUIKit.swift
File metadata and controls
58 lines (56 loc) · 1.68 KB
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
56
57
58
#if canImport(UIKit) && !os(watchOS)
import UIKit
@available(iOS 13, *)
@available(macCatalyst 13, *)
@available(macOS, unavailable)
@available(tvOS 13, *)
@available(watchOS, unavailable)
extension UIAlertController {
/// Creates a `UIAlertController` from a ``Store`` focused on alert state.
///
/// You can use this API with the `UIViewController.present(item:)` method:
///
/// ```swift
/// class FeatureController: UIViewController {
/// @UIBindable var store: StoreOf<Feature>
/// // ...
///
/// func viewDidLoad() {
/// // ...
///
/// present(item: $store.scope(state: \.alert, action: \.alert)) { store in
/// UIAlertController(store: store)
/// }
/// }
/// }
/// ```
public convenience init<Action>(
store: Store<AlertState<Action>, Action>
) {
self.init(state: store.currentState) { _ = $0.map(store.send) }
}
/// Creates a `UIAlertController` from a ``Store`` focused on confirmation dialog state.
///
/// You can use this API with the `UIViewController.present(item:)` method:
///
/// ```swift
/// class FeatureController: UIViewController {
/// @UIBindable var store: StoreOf<Feature>
/// // ...
///
/// func viewDidLoad() {
/// // ...
///
/// present(item: $store.scope(state: \.dialog, action: \.dialog)) { store in
/// UIAlertController(store: store)
/// }
/// }
/// }
/// ```
public convenience init<Action>(
store: Store<ConfirmationDialogState<Action>, Action>
) {
self.init(state: store.currentState) { _ = $0.map(store.send) }
}
}
#endif