2

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

Ali Hamad
  • 599
  • 6
  • 12

1 Answers1

8

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

Ali Hamad
  • 599
  • 6
  • 12