extension String{
func convertHtml() -> NSAttributedString{
guard data(using: .utf8) != nil else { return NSAttributedString() }
do {
return try NSAttributedString(data: Data(utf8),
options: [.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue],
documentAttributes: nil)
} catch {
print("error:", error)
return NSAttributedString()
}
}
}
网友评论