File tree Expand file tree Collapse file tree 4 files changed +57
-20
lines changed
RouterExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm Expand file tree Collapse file tree 4 files changed +57
-20
lines changed Original file line number Diff line number Diff line change @@ -22,13 +22,15 @@ struct RouterExampleApp: App {
22
22
var body: some Scene {
23
23
WindowGroup {
24
24
RouterRootView { router in
25
- EmptyView ()
26
- .onAppear {
27
- if isFirstLaunch {
28
- router.route (" myapp://onboarding1" , .replace )
29
- } else {
30
- router.route (" myapp://content" , .replace )
31
- }
25
+ Switch (isFirstLaunch)
26
+ .Case (true ) { _ in
27
+ OnboardingView ()
28
+ }
29
+ .Case (false ) { _ in
30
+ ContentView ()
31
+ }
32
+ .Else {
33
+ EmptyView ()
32
34
}
33
35
}
34
36
.path (" myapp://onboarding1" ) { _ in
@@ -50,8 +52,23 @@ struct RouterExampleApp: App {
50
52
CounterView (count : data.bindings .count )
51
53
}
52
54
.path (" myapp://color" ) { data in
53
- ColorView (color : MyColor (rawValue : data.color ?? " red" ) ?? .red )
54
- .navigationBarHidden (true )
55
+ If< String > (data.color ).Let { color in
56
+ ColorView (color : MyColor.from (string : color))
57
+ .navigationBarHidden (true )
58
+ }
59
+ // or
60
+ // Switch<String>(data.color)
61
+ // .Case("red") { color in
62
+ // ColorView(color: MyColor.from(string: color))
63
+ // .navigationBarHidden(true)
64
+ // }
65
+ // .Case("green") { color in
66
+ // ColorView(color: MyColor.from(string: color))
67
+ // .navigationBarHidden(true)
68
+ // }
69
+ // .Else {
70
+ // Text("OMG")
71
+ // }
55
72
}
56
73
}
57
74
}
Original file line number Diff line number Diff line change @@ -15,6 +15,10 @@ enum MyColor: String {
15
15
case yellow
16
16
case purple
17
17
case white
18
+
19
+ static func from( string: String ) -> MyColor {
20
+ return MyColor ( rawValue: string) ?? . white
21
+ }
18
22
}
19
23
20
24
struct ColorView : View {
Original file line number Diff line number Diff line change @@ -18,13 +18,15 @@ struct RouterExampleApp: App {
18
18
var body : some Scene {
19
19
WindowGroup {
20
20
RouterRootView { router in
21
- EmptyView ( )
22
- . onAppear {
23
- if isFirstLaunch {
24
- router. route ( " myapp://onboarding1 " , . replace)
25
- } else {
26
- router. route ( " myapp://content " , . replace)
27
- }
21
+ Switch ( isFirstLaunch)
22
+ . Case ( true ) { _ in
23
+ OnboardingView ( )
24
+ }
25
+ . Case ( false ) { _ in
26
+ ContentView ( )
27
+ }
28
+ . Else {
29
+ EmptyView ( )
28
30
}
29
31
}
30
32
. path ( " myapp://onboarding1 " ) { _ in
@@ -46,8 +48,22 @@ struct RouterExampleApp: App {
46
48
CounterView ( count: data. bindings. count)
47
49
}
48
50
. path ( " myapp://color " ) { data in
49
- ColorView ( color: MyColor ( rawValue: data. color ?? " red " ) ?? . red)
50
- . navigationBarHidden ( true )
51
+ If < String > ( data. color) . Let { color in
52
+ ColorView ( color: MyColor . from ( string: color) )
53
+ . navigationBarHidden ( true )
54
+ }
55
+ // Switch<String>(data.color)
56
+ // .Case("red") { color in
57
+ // ColorView(color: MyColor.from(string: color))
58
+ // .navigationBarHidden(true)
59
+ // }
60
+ // .Case("green") { color in
61
+ // ColorView(color: MyColor.from(string: color))
62
+ // .navigationBarHidden(true)
63
+ // }
64
+ // .Else {
65
+ // Text("OMG")
66
+ // }
51
67
}
52
68
}
53
69
}
You can’t perform that action at this time.
0 commit comments