Wednesday, February 16, 2022

Surprises When Using Markdown in SwiftUI

Marco Eidinger (via Dave Verwer):

A nice surprise is that SwiftUI supports GitHub Flavored Markdown (GFM). […] An Apple engineer confirmed the use of GFM in the Apple Developer forum.


Using a string literal in Text works. Fine, but using a string variable does not! […] The trick is to use init(_:) of LocalizedStringKey.


You might run into the situation that you have an AttributedString with line breaks (\n), but those line breaks are not displayed.

The trick is to add the .inlineOnlyPreservingWhitespace option when initializing the AttributedString.

Comments RSS · Twitter

Leave a Comment