'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 🤔



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ali Hamad