回答編集履歴
1
追記
test
CHANGED
@@ -43,3 +43,71 @@
|
|
43
43
|
}
|
44
44
|
|
45
45
|
```
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
---
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
print 以外のことをしたいなら、例えばこんな感じ。(濫用しない方がいいと思いますが。)
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
```swift
|
58
|
+
|
59
|
+
extension View {
|
60
|
+
|
61
|
+
func DoIt(_ f: () -> Void) -> some View {
|
62
|
+
|
63
|
+
f()
|
64
|
+
|
65
|
+
return EmptyView()
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
struct ContentView: View {
|
74
|
+
|
75
|
+
@State var array = [0, 1, 2]
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
var body: some View {
|
80
|
+
|
81
|
+
ForEach(array, id: .self) { count in
|
82
|
+
|
83
|
+
if count == 0 {
|
84
|
+
|
85
|
+
DoIt {
|
86
|
+
|
87
|
+
print("0番固定の処理")
|
88
|
+
|
89
|
+
if array.count < 6 {
|
90
|
+
|
91
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
92
|
+
|
93
|
+
array.append(3)
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
Text("Hello, world! (count)")
|
104
|
+
|
105
|
+
.padding()
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
```
|