Created
October 27, 2019 09:31
-
-
Save sooch/0a8f2d08f521f8275f7fa80274d914d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
func asHtmlAttributedString() -> NSAttributedString? { | |
guard let htmlData = self.data(using: String.Encoding.utf8, allowLossyConversion: true) else { return nil } | |
let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [ | |
.documentType: NSAttributedString.DocumentType.html, | |
.characterEncoding: String.Encoding.utf8.rawValue | |
] | |
return try? NSAttributedString(data: htmlData, options: options, documentAttributes: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment