我正在尝试将RSS Feed从RSS Feed转换为String并在UILabel中显示。
这是我在String扩展中的代码:
var html2AttributedString: NSAttributedString? {
guard
let data = data(using: String.Encoding.utf8)
else { return nil }
do {
return try NSAttributedString(data: data , options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil)
} catch {
print("error:", error)
return nil
}
}
var html2String: String {
return html2AttributedString?.string ?? ""
}
我在这里称之为:
self.lblDescription.text = article.articleDescription.html2String
当我运行应用程序时,此代码正常工作,从未崩溃。但是当我在TestUI中运行此代码时,它有时会崩溃(5个中的2个):
let app = XCUIApplication()
let tablesQuery = app.tables
这是错误:
Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1827ece5c)
0x10095a350 <+132>: ldr x21, [sp, #0x40]
0x10095a354 <+136>: bl 0x10095c7d4 ; @nonobjc (extension in UIKit):__ObjC.NSAttributedString.init(data: Foundation.Data, options: Swift.Dictionary<Swift.String, Any>, documentAttributes: Swift.Optional<Swift.AutoreleasingUnsafeMutablePointer<Swift.Optional<__ObjC.NSDictionary>>>) throws -> __ObjC.NSAttributedString at AppExtensions.swift
-> 0x10095a358 <+140>: mov x8, x21
0x10095a35c <+144>: mov x1, x8