LoginSignup
14
6

More than 5 years have passed since last update.

Swift「Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions」が出た時の対処

Posted at

Swiftでコードを書いていたら、こんなエラーが出て、コンパイルできない。。。

Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions

該当の箇所はこんな感じ。
※計算式は適当ですが…

let x : CGFloat = CGFloat((320 / 4 - 140 / 2) + (15 * (i % 2)) + (320 * (i % 2)))

これ、()が多いって言われているんですね。
なので、もっとわかりやすく書き換えなさいっていうお達し。

なので、こうしたら、コンパイルできました。

let x =(320 / 4 - 140 / 2)
let y =(15 * (i % 2))
let z = (320 * (i % 2))
let xyz : CGFloat = CGFloat(x + y + z)

複雑なのはよくないってことなんでしょうね。
ということで、分割して解決。

参考:http://stackoverflow.com/questions/25569373/swift-compound-arithmetic-operation-error

14
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
6