【发布时间】:2020-04-21 00:19:44
【问题描述】:
将 html 转换为属性字符串时应用程序很少崩溃。
var htmlToAttributedString: NSAttributedString? {
guard let data = data(using: .utf8) else { return NSAttributedString() }
do {
return try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding:String.Encoding.utf8.rawValue], documentAttributes: nil)
} catch {
return NSAttributedString()
}
}
```
【问题讨论】:
-
发生时有任何崩溃日志吗?
-
与您的崩溃无关,但如果您从未真正返回
nil而是返回一个空字符串,则将变量声明为Optional<NSAttributedString>是没有意义的。
标签: ios swift nsattributedstring