fs_tigre
fs_tigre

Reputation: 10738

Concatenate and display a string variable and a symbol in a Text view in SwiftUI

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?

Upvotes: 0

Views: 1381

Answers (2)

Asperi
Asperi

Reputation: 257709

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

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

Upvotes: 3

Raja Kishan
Raja Kishan

Reputation: 18924

Insert like this

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

Upvotes: 2

Related Questions