Home > OS >  Wrap truncated text in Double quotes in SwiftUI
Wrap truncated text in Double quotes in SwiftUI

Time:05-05

Expected result (Truncated text wrapped in double-quotes): "Let's figure out your preferen..."

I tried using

Text("\"\(description)\"")
    .lineLimit(1)

but unable to get a double quote at the end "Let's figure out your preferen...

CodePudding user response:

As others have said, you should give us some ideas of what you have tried. One possible solution can be the following.

struct ContentView: View {

let description: String = "Let's figure out your preferences and interests for this trip and get your trip sorted with the best recommendations that work for you"



   var body: some View {
        Text("\"\(description)\"")
            .padding()
    }
}

CodePudding user response:

You have to individually escape each character. The following code would show a double quote at the end.

Text("\" This will show double quotes at the start and end \"")

This is done via escaping - you need to put a \ in front of each character that should be taken as a text character instead of code. Note how the code above is highlighted too - only the first and last quotes are part of the code, so only they are in a different color.

  • Related