Skip to content

Instantly share code, notes, and snippets.

@askarsyzdykov
Created March 5, 2017 18:21
Show Gist options
  • Save askarsyzdykov/9b7586f1dd35ccf903c44f10ddde8f67 to your computer and use it in GitHub Desktop.
Save askarsyzdykov/9b7586f1dd35ccf903c44f10ddde8f67 to your computer and use it in GitHub Desktop.
extension String {
var html2AttributedString: NSAttributedString? {
guard let data = data(using: .utf8) else {
return nil
}
do {
return try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil)
} catch let error as NSError {
print(error.localizedDescription)
return nil
}
}
var html2String: String {
return html2AttributedString?.string ?? ""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment