「The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions」とエラーが表示された時の解決方法

swift
The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

SwiftUIで開発をしていると、上記のエラーをよく見ることとなります。

日本語訳をすると、

swift
この式が複雑すぎてコンパイラが型推論を合理的な時間内に完了できません式を分割してください。」

という意味になります。

特にvar body: some View {}が記述されている行での発生した場合は、上記のエラー内容の意味は関係なくvar body: some View {}内の文法ミスによって発生していることが大半です。

新たに追加した記述をコメントアウトするなどして、エラーがの発生箇所を見つけるようにしましょう。

関連記事