Reputation: 10738
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"))")
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
Reputation: 257709
Next variant also works (for example if needed in ForEach
, etc.)
Text(someText) + Text(Image(systemName: "star"))
Upvotes: 3
Reputation: 18924
Insert like this
Text("\(someText) \(Image(systemName: "star"))")
Upvotes: 2