首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将NSAttributedString转换为NSStringEncoding时检测到错误的HTML值0x8000100

将NSAttributedString转换为NSStringEncoding时检测到错误的HTML值0x8000100
EN

Stack Overflow用户
提问于 2021-01-27 01:16:47
回答 1查看 155关注 0票数 0

我在XCode中的调试器中收到警告:在将NSAttributedString转换为NSStringEncoding数据时检测到错误的html值0x8000100。不确定导致此问题的原因或如何修复此问题。下面是我的代码:

代码语言:javascript
复制
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)

数据确实被创建了,但我不确定为什么会收到警告。

EN

回答 1

Stack Overflow用户

发布于 2021-02-02 07:21:59

我终于弄清楚是什么导致了这一切。看起来字符串转数据函数想知道要使用什么文本编码。以下是删除调试器警告的修复代码:

代码语言:javascript
复制
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)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65906014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档