Home > Net >  Concatenate and display a string variable and a symbol in a Text view in SwiftUI
Concatenate and display a string variable and a symbol in a Text view in SwiftUI

Time:08-21

I need to concatenate and display a string variable and a symbol in a Text view in SwiftUI, I basically need the effect you get when using string interpolation as follows...

Text("Some Text \(Image(systemName: "star"))")

enter image description here

I basically need to display text and a symbol but the text comes from a variable, something like the following which gives me an error...

    let someText = "Some Text"
    let someTextPlusImage = someText   Text(Image(systemName: "star")

    Text(someTextPlusImage)

Error:

error: Segmentation fault: 11

How can I concatenate and display a string variable and a symbol in a Text view in SwiftUI?

CodePudding user response:

Insert like this

Text("\(someText) \(Image(systemName: "star"))")

CodePudding user response:

Next variant also works (for example if needed in ForEach, etc.)

Text(someText)   Text(Image(systemName: "star"))
  • Related