forked from ole/swiftui-view-lifecycle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCaseStudySwitch.swift
43 lines (37 loc) · 1.12 KB
/
CaseStudySwitch.swift
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
import SwiftUI
enum Cases {
case one
case two
case three
}
struct CaseStudySwitch: View {
@State private var state: Cases = .one
var body: some View {
VStack {
Picker("Selection", selection: $state) {
Text("One").tag(Cases.one)
Text("Two").tag(Cases.two)
Text("Three").tag(Cases.three)
}
.pickerStyle(.segmented)
switch state {
case .one:
LifecycleMonitor(label: "One")
case .two:
LifecycleMonitor(label: "Two")
case .three:
LifecycleMonitor(label: "Three")
}
Text("A `switch` statement behaves like a series of `if`/`else` branches. Content views are fully destroyed and recreated as you switch between states.")
.font(.callout)
.frame(maxWidth: .infinity, alignment: .leading)
}
.padding()
.navigationTitle("switch")
}
}
struct CaseStudySwitch_Previews: PreviewProvider {
static var previews: some View {
CaseStudySwitch()
}
}