I found this string extension somewhere on SO that allows me to turn html code into an attributed string:
func html2AttributedString() -> NSAttributedStri
This works for me:
let attrStr = try! NSAttributedString(
data: modifiedFont.data(using: .unicode, allowLossyConversion: true)!,
options:[.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue],
documentAttributes: nil)
If you don’t add
.characterEncoding: String.Encoding.utf8.rawValue
the app will crash.