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