Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Text Markdown support for string variables or string interpolation not working [duplicate]

I'm trying to show my response data using SwiftUI Text with formatted text ex: Bold, but for some reason it's not working 🤔

The needed behaviour as below:

enter image description here

This is working!

Text("**Hello** *World*")

But this is not 🤔

let text: String = "**Hello** *World*"
Text(text)

Am I missing something 🤔

like image 707
Ali Hamad Avatar asked Jun 10 '26 17:06

Ali Hamad


1 Answers

After test and fail moments, I found that Text only handles markdown when string literal is passed to initializer. as below:

to achieve the needed behavior:

let text: String = "**Hello** *World*"
    
Text("**Hello** *World*") // will be rendered with markdown formatting
Text(text) // will NOT be rendered according to markdown
Text(.init(text)) // will be rendered with markdown formatting

enter image description here

like image 104
Ali Hamad Avatar answered Jun 16 '26 11:06

Ali Hamad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!