Break Line

When I use: Text("My text \nhas a break line") The output is: My text has a break line PERFECT - I have "My text" and in the next line, I have "has a break line"

However if I have: Text(mymodel.description)
//where this is returning from an API call and mymodel.description contains "My text \nhas a break line") It doesn't work. The output is: My text \nhas a break line

Why ?

Answered by ForumsContributor in
Accepted Answer

Cannot reproduce the issue. Works for me on macos 12.beta, xcode 13.beta, target ios 14.7 and macCatalyst 12. Tested on macOS 12 and iPhone ios 14.7.


import SwiftUI

@main
struct TestApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
struct ContentView: View {
    @State var test = "My text \nhas a break line"
    let test2 = "My text \nhas a break line"

    var body: some View {
        VStack (spacing: 30) {
            Text(test)
            Text(test.description)
            Text("\(test)")
            Text(test2)
        }
    }
}
Break Line
 
 
Q