1
+ #if canImport(SwiftUI)
1
2
import SwiftUI
2
3
3
4
/// A view that can switch over a store of enum state and handle each case.
@@ -44,6 +45,7 @@ import SwiftUI
44
45
/// - See also: `Reducer.pullback`, a method that aids in transforming reducers that operate on each
45
46
/// case of an enum into reducers that operate on the entire enum.
46
47
///
48
+ @available ( iOS 13 , macOS 10 . 15 , macCatalyst 13 , tvOS 13 , watchOS 6 , * )
47
49
public struct SwitchStore < State, Action, Content> : View where Content: View {
48
50
public let store : Store < State , Action >
49
51
public let content : ( ) -> Content
@@ -63,6 +65,7 @@ public struct SwitchStore<State, Action, Content>: View where Content: View {
63
65
}
64
66
65
67
/// A view that handles a specific case of enum state in a `SwitchStore`.
68
+ @available ( iOS 13 , macOS 10 . 15 , macCatalyst 13 , tvOS 13 , watchOS 6 , * )
66
69
public struct CaseLet < GlobalState, GlobalAction, LocalState, LocalAction, Content> : View
67
70
where Content: View {
68
71
@EnvironmentObject private var store : StoreObservableObject < GlobalState , GlobalAction >
@@ -104,6 +107,7 @@ where Content: View {
104
107
/// If you wish to use `SwitchStore` in a non-exhaustive manner (i.e. you do not want to provide
105
108
/// a `CaseLet` for each case of the enum), then you must insert a `Default` view at the end of
106
109
/// the `SwitchStore`'s body.
110
+ @available ( iOS 13 , macOS 10 . 15 , macCatalyst 13 , tvOS 13 , watchOS 6 , * )
107
111
public struct Default < Content> : View where Content: View {
108
112
private let content : ( ) -> Content
109
113
@@ -121,6 +125,7 @@ public struct Default<Content>: View where Content: View {
121
125
}
122
126
}
123
127
128
+ @available ( iOS 13 , macOS 10 . 15 , macCatalyst 13 , tvOS 13 , watchOS 6 , * )
124
129
extension SwitchStore {
125
130
public init < State1, Action1, Content1, DefaultContent> (
126
131
_ store: Store < State , Action > ,
@@ -529,6 +534,7 @@ extension SwitchStore {
529
534
}
530
535
}
531
536
537
+ @available ( iOS 13 , macOS 10 . 15 , macCatalyst 13 , tvOS 13 , watchOS 6 , * )
532
538
public struct _ExhaustivityCheckView < State, Action> : View {
533
539
@EnvironmentObject private var store : StoreObservableObject < State , Action >
534
540
let file : StaticString
@@ -539,7 +545,7 @@ public struct _ExhaustivityCheckView<State, Action>: View {
539
545
let message = """
540
546
Warning: SwitchStore.body@ \( self . file) : \( self . line)
541
547
542
- " \( debugCaseOutput ( self . store. wrappedValue. state. value) ) " was encountered by a \
548
+ " \( debugCaseOutput ( self . store. wrappedValue. $ state. value) ) " was encountered by a \
543
549
" SwitchStore " that does not handle this case.
544
550
545
551
Make sure that you exhaustively provide a " CaseLet " view for each case in " \( State . self) " , \
@@ -574,6 +580,7 @@ public struct _ExhaustivityCheckView<State, Action>: View {
574
580
}
575
581
}
576
582
583
+ @available ( iOS 13 , macOS 10 . 15 , macCatalyst 13 , tvOS 13 , watchOS 6 , * )
577
584
private class StoreObservableObject < State, Action> : ObservableObject {
578
585
let wrappedValue : Store < State , Action >
579
586
@@ -599,3 +606,4 @@ private struct EnumValueWitnessTable {
599
606
let getEnumTag : @convention ( c) ( UnsafeRawPointer , UnsafeRawPointer ) -> UInt32
600
607
let f13 , f14 : UnsafeRawPointer
601
608
}
609
+ #endif
0 commit comments