Created
March 5, 2017 18:21
-
-
Save askarsyzdykov/9b7586f1dd35ccf903c44f10ddde8f67 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 { | |
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