1

I write this code in Xcode, you can try it on playground.

let constraintSize = CGSize(width: 500.0 - 55.0 - 35.0 - 60.0 - 10.0 - 15.0, height: 9999)

the compiler tell this message

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

too complex expression in Swift

Any ideas why the compiler tell this silly message, since it is clear that it's just a simple calculation.

nRewik
  • 8,958
  • 4
  • 23
  • 30

2 Answers2

1

The compiler doesn't like to have expressions as function parameters.

I guess it's more a source code parsing problem than a calculation problem.

The solution is obvious:

let width = 500.0 - 55.0 - 35.0 - 60.0 - 10.0 - 15.0
let constraintSize = CGSize(width: width, height: 9999)
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
1

Well, obviously this is a language issue. Compiler should have been able to execute this simple expression. However, in some cases its been observed that long expressions eat up 100% CPU leading to deadlock.

Look at this thread and this thread for more information. Guess you already know the solution in your case so not posting it :).

Community
  • 1
  • 1
Abhinav
  • 37,684
  • 43
  • 191
  • 309