Created
January 21, 2023 10:44
-
-
Save raberm/a8097399f37eee604e98b4b1e50202dc to your computer and use it in GitHub Desktop.
html to NSAttributedString
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 htmlAttributedString() -> NSAttributedString? { | |
guard let data = self.data(using: String.Encoding.utf16, allowLossyConversion: false) else { return nil } | |
guard let html = try? NSMutableAttributedString( | |
data: data, | |
options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], | |
documentAttributes: nil) else { return nil } | |
return html | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment