/
ContentView.swift
67 lines (60 loc) · 1.45 KB
/
ContentView.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import SwiftUI
// MARK: - ContentView
struct ContentView: View {
// Regular direct use of outer ObservableObject
@StateObject var viewModel: ViewModel
var body: some View {
ScrollView {
VStack(alignment: .center, spacing: 24) {
Spacer()
Text(viewModel.countString)
.font(.title)
.fontWeight(.bold)
.scaledToFit()
Text(viewModel.info)
.font(.body.monospaced())
Spacer()
VStack(alignment: .center, spacing: 24) {
Spacer()
CapsuleButton(
bg: (1, 0, 0, 0),
fg: 1,
text: "count += 1"
) {
viewModel.increment()
}
CapsuleButton(
bg: (0, 1, 0, 0),
fg: 1,
text: "count -= 1"
) {
viewModel.decrement()
}
CapsuleButton(
bg: (0, 0, 1, 0),
fg: 0,
text: "count = rand()"
) {
viewModel.rand()
}
CapsuleButton(
bg: (0, 0, 0, 1),
fg: 1,
text: "count = 0"
) {
viewModel.zero()
}
Spacer()
}
}
.frame(maxWidth: .infinity)
}
.background(.gray.opacity(0.6))
}
}
// MARK: - ContentView_Previews
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(viewModel: ViewModel(model: DomainModel()))
}
}