回答編集履歴

1

fix typo

2019/09/19 03:09

投稿

kechizenya
kechizenya

スコア34

test CHANGED
@@ -234,35 +234,77 @@
234
234
 
235
235
 
236
236
 
237
+ struct FirstView: View {
238
+
239
+ @ObservedObject var vm = ViewModel() // インスタンスを生成
240
+
241
+
242
+
243
+ var body: some View {
244
+
245
+ VStack {
246
+
247
+ SecondView()
248
+
249
+ .environmentObject(vm)
250
+
251
+ // SecondView 以下に @EnvironmentObject を設定
252
+
253
+
254
+
255
+ Text("(vm.name)")
256
+
257
+ }
258
+
259
+ }
260
+
261
+ }
262
+
263
+
264
+
265
+ struct SecondView: View {
266
+
267
+ @EnvironmentObject var vm: ViewModel
268
+
269
+
270
+
271
+ var body: some View {
272
+
273
+ VStack {
274
+
275
+ TextField("Placeholder", text: $vm.name)
276
+
277
+ ThirdView()
278
+
279
+ }
280
+
281
+ }
282
+
283
+ }
284
+
285
+
286
+
237
287
  struct ThirdView: View {
238
288
 
239
- @ObservedObject var vm = ViewModel() // インスタンスを生成
240
-
241
-
242
-
243
- var FirstView: some View {
289
+ var body: some View {
244
-
290
+
245
- VStack {
291
+ VStack {
246
-
247
- SecondView()
292
+
248
-
249
- .environmentObject(vm)
250
-
251
- // SecondView 以下に @EnvironmentObject を設定
252
-
253
-
254
-
255
- Text("(vm.name)")
293
+ Text("hoge hoge")
294
+
256
-
295
+ FourthView()
296
+
257
- }
297
+ }
258
-
298
+
259
- }
299
+ }
300
+
260
-
301
+ // 共有された変数を使わないビューは @EnvironmentObject の記述を省略可能
302
+
261
- }
303
+ }
262
-
263
-
264
-
304
+
305
+
306
+
265
- struct SecondView: View {
307
+ struct FourthView: View {
266
308
 
267
309
  @EnvironmentObject var vm: ViewModel
268
310
 
@@ -270,48 +312,6 @@
270
312
 
271
313
  var body: some View {
272
314
 
273
- VStack {
274
-
275
- TextField("Placeholder", text: $vm.name)
276
-
277
- ThirdView()
278
-
279
- }
280
-
281
- }
282
-
283
- }
284
-
285
-
286
-
287
- struct ThirdView: View {
288
-
289
- var body: some View {
290
-
291
- VStack {
292
-
293
- Text("hoge hoge")
294
-
295
- FourthView()
296
-
297
- }
298
-
299
- }
300
-
301
- // 共有された変数を使わないビューは @EnvironmentObject の記述を省略可能
302
-
303
- }
304
-
305
-
306
-
307
- struct FourthView: View {
308
-
309
- @EnvironmentObject var vm: ViewModel
310
-
311
-
312
-
313
- var body: some View {
314
-
315
315
  Text(vm.name)
316
316
 
317
317
  }