iOS Development
ios – Why when creating NSAttributedString from html typically app throws exception “The file couldn’t be opened as a result of it isn’t within the appropriate format.”

I’ve these extensions to parse string with html tags to NSAttributedString
extension StringProtocol {
var html2AttributedString: NSAttributedString? {
Knowledge(utf8).html2AttributedString
}
}
extension Knowledge {
var html2AttributedString: NSAttributedString? {
do {
return strive NSAttributedString(
information: self,
choices: [
.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue
],
documentAttributes: nil)
} catch {
bfprint("html2AttributedString: Html string parsing error: (error)",
tag: LogUtils.Tags.criticalDevError,
degree: .error)
return nil
}
}
}
The app will get unique html strings from Localizable recordsdata. Generally when the app parses the html strings with <u> tag like this “That is <u>underlined half</u>” I see this error log:
html2AttributedString: Html string parsing error: Error Area=NSCocoaErrorDomain Code=259 “The file couldn’t be opened as a result of it isn’t within the appropriate format.”
I’ve learn official doc and did not discover any pitfalls that would trigger the issue. Additionally I did not discover any comparable questions associated to getting NSAttributedString
Credit: www.ismmailgsm.com