Reputation: 2458
I have a strange behavior within swift playground.
When I enter this lines of code
println("test 1" + "test 2" + "test 3" + "test 4") //compiles
println("test 1" + "test 2" + "test 3" + "test 4" + "test 5") //compiles
println("test 1" + "test 2" + "test 3" + "test 4" + "test 5" + "test 6") //error!
The last line of code does not compile. The error is:
Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions
Am I doing something wrong, or is this some kind of a bug? It seems like the limit for println() is 5 string concatenations?
Upvotes: 2
Views: 142
Reputation: 385580
You're not doing anything wrong. Apple is.
The println
function is the problem, not string concatenation. This gives me the same error:
println(1 + 2 + 3 + 4 + 5 + 6)
You can work around it by declaring your own wrapper:
func myprint<T>(x: T) {
println(x)
}
myprint(1 + 2 + 3 + 4 + 5 + 6)
myprint("1" + "2" + "3" + "4" + "5" + "6")
myprint("1" + "2" + "3" + "4" + "5" + "6" + "1" + "2" + "3" + "4" + "5" + "6")
Output:
21
123456
123456123456
Upvotes: 2