我使用这种方式,它工作正常,但有一个缓慢回落,因为NSHTMLTextDocumentType的使用为我做了我的研究显示HTML内容有效
do {
let attributedOptions:[String: Any] = [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue]
let date = html.data(using: String.Encoding.utf8, allowLossyConversion: true)!
return try NSAttributedString(data: data, options: attributedOptions , documentAttributes: nil)
} catch let error as NSError {
print("htmo2String \(error)")
}
任何想法如何做到这一点的速度更快或另一种有效的方式来做到这一点!
或缓存它:将它与您的异步解析保存到HTML来自对象 – muescha
做它在队列上的异步似乎是一个好主意 –