You can add this extension to convert your html code to a regular string:

来源:互联网 发布:开淘宝店投资多少 编辑:程序博客网 时间:2024/05/04 17:58
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 ?? ""    }}
0 0
原创粉丝点击