我在XCode中的调试器中收到警告:在将NSAttributedString转换为NSStringEncoding数据时检测到错误的html值0x8000100。不确定导致此问题的原因或如何修复此问题。下面是我的代码:
let testString = NSAttributedString(string: "test")
let documentAttributes: [NSAttributedString.DocumentAttributeKey: Any] = [.documentType: NSAttributedString.DocumentType.html]
let htmlData = try? testString.data(from: NSRange(location: 0, length: testString.length), documentAttributes: documentAttributes)数据确实被创建了,但我不确定为什么会收到警告。
发布于 2021-02-02 07:21:59
我终于弄清楚是什么导致了这一切。看起来字符串转数据函数想知道要使用什么文本编码。以下是删除调试器警告的修复代码:
let testString = NSAttributedString(string: "test")
let documentAttributes: [NSAttributedString.DocumentAttributeKey: Any] = [.documentType: NSAttributedString.DocumentType.html, .characterEncoding:String.Encoding.utf8.rawValue]
let htmlData = try? testString.data(from: NSRange(location: 0, length: testString.length), documentAttributes: documentAttributes)https://stackoverflow.com/questions/65906014
复制相似问题