Text with concatenated string fails to build

Good afternoon

Anyone knows a reason why this fails to build?

Text(order.firstName + " " + order.lastName + "\n" + order.address + "\n" + order.ZIP + " " + order.city)

Gives always:

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

But this works:

Text(order.firstName + " " + order.lastName + "\n" + order.address)

Is there a limit of number of lines I could use with Text()?

thanks in advance richard

Replies

Problem is that compiler has too much type check to do and cannot do it directly in Text. It is not the number of lines but number of types to check (because of the +, it has many options to test for each +, causing an exponential explosion (a real limit of the compiler here).

You could define a computed var in Order:

Struct Order {
  var firstName : String = "" Whatever you want
  // etc

    var description = lastName + "\n" +address + ZIP + " " + city
}

And use it in Text:

Text(order.description)

Yeah..figured this out just before....using this now (works but maybe not the correct way ;o):

let address = order.firstName + " " + order.lastName + "\n" + order.address + "\n" + orderZIP + " " + order.city
Text(address)

But a computed var might be even better...

Yepp this works:

var Adresszeile: String { return firstName + " " + lastName + "\n" + address + "\n" + ZIP + " " + city }

Hmm...can I concatenate a String conditionally? Like add it only when it is not empty?

Some orders might have a company name filled out which should go into the address lines after the name...