どこがエラーか良くわからない!!!
そんなとき。。。。viewの中で普段使いそうなワードを使うと。。。
初心者にはなかなか手厳しい^^
知っている方にはそれはそう!ということですがなんとなく書いていると。。。
エラーになりますね
文法 | 使える? | 代替方法 |
---|---|---|
for in | ❌ | ForEach |
if let | ❌ | .map() や if を使う |
guard | ❌ | if を使う |
switch | ❌ | if を使う |
return | ❌ | return を省略 |
while | ❌ | ForEach |
try / catch | ❌ | .task + do-catch |
SwiftUI では、ForEach
を活用し、条件分岐は if
を使うのが基本 になります。
エラーを見ておきます
for in
Closure containing control flow statement cannot be used with result builder 'ViewBuilder'
if let
(オプショナルバインディング)
Closure containing control flow statement cannot be used with result builder ‘ViewBuilder’
guard
switch
Closure containing control flow statement cannot be used with result builder ‘ViewBuilder’
return
Unexpected ‘return’ in function expected to return ‘some View’
returnはわかりますが
Closure containing control flow statement cannot be used
「制御フロー文を含むクロージャは使用できません」
答えが出ましたね^^; 英語難しいな〜
コメント