SwiftUI Text inside Text interpolation bug?

Why the does this display "Hello1" and not "HelloWorld"? Then if I put a space between them it works as expected.

(macOS 12.0.1)

struct ContentView: View {
    var body: some View {
        let t1 = Text("Hello").foregroundColor(.red)
        let t2 = Text("World").foregroundColor(.blue)
        Text("\(t1)\(t2)")
            .padding()
            .frame(width: 200)
    }
}

Strange indeed. Same behaviour in iOS.

Where does this 1 in Hello1 come from ? Is it the 1 of True bool ?

The reason is likely because t1 is not a String (or an AttributedString), but a Text view. It is even surprising that interpolation works. Probably, SwiftUI extracts the attributedText from the TextStorage of the Text View, and fails in some cases.

I tried the following variation to illustrate:

      let t1 = Text("Hello").foregroundColor(.red)
      let t2 = Text("World").foregroundColor(.blue)
      let s1 = "\(t1)\(t2)"
      Text(s1) // Instead of -->> Text("\(t1)\(t2)")
          .padding()
          .frame(width: 200)

I get a totally different result :

That's worth a bug report or at least a contact to support team.

SwiftUI Text inside Text interpolation bug?
 
 
Q