質問編集履歴
2
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -120,6 +120,156 @@
|
|
120
120
|
|
121
121
|
|
122
122
|
|
123
|
+
struct ContentView: View {
|
124
|
+
|
125
|
+
@ObservedObject var Num = ShareNum()
|
126
|
+
|
127
|
+
var body: some View {
|
128
|
+
|
129
|
+
VStack{
|
130
|
+
|
131
|
+
Text("(Num.num)")
|
132
|
+
|
133
|
+
HStack{
|
134
|
+
|
135
|
+
button1()
|
136
|
+
|
137
|
+
button2()
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
struct ContentView_Previews: PreviewProvider {
|
150
|
+
|
151
|
+
static var previews: some View {
|
152
|
+
|
153
|
+
ContentView()
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
```
|
162
|
+
|
163
|
+
```button1
|
164
|
+
|
165
|
+
#button1.swift
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
import SwiftUI
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
struct button1: View {
|
174
|
+
|
175
|
+
@ObservedObject var Num = ShareNum()
|
176
|
+
|
177
|
+
var body: some View {
|
178
|
+
|
179
|
+
Button(action: {
|
180
|
+
|
181
|
+
self.Num.PlusButton()
|
182
|
+
|
183
|
+
}) {
|
184
|
+
|
185
|
+
Image(systemName: "plus")
|
186
|
+
|
187
|
+
.frame(width: 40, height: 40)
|
188
|
+
|
189
|
+
.imageScale(.large)
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
.background(Color.blue)
|
194
|
+
|
195
|
+
.foregroundColor(.black)
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
struct button1_Previews: PreviewProvider {
|
204
|
+
|
205
|
+
static var previews: some View {
|
206
|
+
|
207
|
+
button1(Num: ShareNum())
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
```
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
```button2
|
220
|
+
|
221
|
+
#button2.swift
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
import SwiftUI
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
struct button2: View {
|
230
|
+
|
231
|
+
@ObservedObject var Num = ShareNum()
|
232
|
+
|
233
|
+
var body: some View {
|
234
|
+
|
235
|
+
Button(action: {
|
236
|
+
|
237
|
+
self.Num.MinusButton()
|
238
|
+
|
239
|
+
}) {
|
240
|
+
|
241
|
+
Image(systemName: "minus")
|
242
|
+
|
243
|
+
.frame(width: 40, height: 40)
|
244
|
+
|
245
|
+
.imageScale(.large)
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
.background(Color.red)
|
250
|
+
|
251
|
+
.foregroundColor(.black)
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
struct button2_Previews: PreviewProvider {
|
260
|
+
|
261
|
+
static var previews: some View {
|
262
|
+
|
263
|
+
button2(Num: ShareNum())
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
```
|
270
|
+
|
271
|
+
```Share
|
272
|
+
|
123
273
|
class ShareNum: ObservableObject{
|
124
274
|
|
125
275
|
@Published var num: Int = 3
|
@@ -142,176 +292,4 @@
|
|
142
292
|
|
143
293
|
}
|
144
294
|
|
145
|
-
struct ContentView: View {
|
146
|
-
|
147
|
-
@ObservedObject var Num = ShareNum()
|
148
|
-
|
149
|
-
var body: some View {
|
150
|
-
|
151
|
-
VStack{
|
152
|
-
|
153
|
-
Text("(Num.num)")
|
154
|
-
|
155
|
-
HStack{
|
156
|
-
|
157
|
-
button1()
|
158
|
-
|
159
|
-
button2()
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
}
|
166
|
-
|
167
|
-
}
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
struct ContentView_Previews: PreviewProvider {
|
172
|
-
|
173
|
-
static var previews: some View {
|
174
|
-
|
175
|
-
ContentView()
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
```
|
295
|
+
```
|
184
|
-
|
185
|
-
```button1
|
186
|
-
|
187
|
-
#button1.swift
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
import SwiftUI
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
struct button1: View {
|
196
|
-
|
197
|
-
@ObservedObject var Num = ShareNum()
|
198
|
-
|
199
|
-
var body: some View {
|
200
|
-
|
201
|
-
Button(action: {
|
202
|
-
|
203
|
-
self.Num.PlusButton()
|
204
|
-
|
205
|
-
}) {
|
206
|
-
|
207
|
-
Image(systemName: "plus")
|
208
|
-
|
209
|
-
.frame(width: 40, height: 40)
|
210
|
-
|
211
|
-
.imageScale(.large)
|
212
|
-
|
213
|
-
}
|
214
|
-
|
215
|
-
.background(Color.blue)
|
216
|
-
|
217
|
-
.foregroundColor(.black)
|
218
|
-
|
219
|
-
}
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
struct button1_Previews: PreviewProvider {
|
226
|
-
|
227
|
-
static var previews: some View {
|
228
|
-
|
229
|
-
button1(Num: ShareNum())
|
230
|
-
|
231
|
-
}
|
232
|
-
|
233
|
-
}
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
```
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
```button2
|
242
|
-
|
243
|
-
#button2.swift
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
import SwiftUI
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
struct button2: View {
|
252
|
-
|
253
|
-
@ObservedObject var Num = ShareNum()
|
254
|
-
|
255
|
-
var body: some View {
|
256
|
-
|
257
|
-
Button(action: {
|
258
|
-
|
259
|
-
self.Num.MinusButton()
|
260
|
-
|
261
|
-
}) {
|
262
|
-
|
263
|
-
Image(systemName: "minus")
|
264
|
-
|
265
|
-
.frame(width: 40, height: 40)
|
266
|
-
|
267
|
-
.imageScale(.large)
|
268
|
-
|
269
|
-
}
|
270
|
-
|
271
|
-
.background(Color.red)
|
272
|
-
|
273
|
-
.foregroundColor(.black)
|
274
|
-
|
275
|
-
}
|
276
|
-
|
277
|
-
}
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
struct button2_Previews: PreviewProvider {
|
282
|
-
|
283
|
-
static var previews: some View {
|
284
|
-
|
285
|
-
button2(Num: ShareNum())
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
}
|
290
|
-
|
291
|
-
```
|
292
|
-
|
293
|
-
```Share
|
294
|
-
|
295
|
-
class ShareNum: ObservableObject{
|
296
|
-
|
297
|
-
@Published var num: Int = 3
|
298
|
-
|
299
|
-
func PlusButton(){
|
300
|
-
|
301
|
-
self.num += 1
|
302
|
-
|
303
|
-
print(self.num)
|
304
|
-
|
305
|
-
}
|
306
|
-
|
307
|
-
func MinusButton(){
|
308
|
-
|
309
|
-
self.num -= 1
|
310
|
-
|
311
|
-
print(self.num)
|
312
|
-
|
313
|
-
}
|
314
|
-
|
315
|
-
}
|
316
|
-
|
317
|
-
```
|