加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – Swift-3错误:’ – [_ SwiftValue unsignedIntegerValue

发布时间:2020-12-15 01:45:56 所属栏目:百科 来源:网络整理
导读:以下代码与旧swift完美配合.这是String的扩展 func stringByConvertingHTML() - String { let newString = replacingOccurrences(of: "n",with: "br") if let encodedData = newString.data(using: String.Encoding.utf8) { let attributedOptions : [Strin
以下代码与旧swift完美配合.这是String的扩展

func stringByConvertingHTML() -> String {
    let newString = replacingOccurrences(of: "n",with: "<br>")
    if let encodedData = newString.data(using: String.Encoding.utf8) {
        let attributedOptions : [String: AnyObject] = [
            NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType as AnyObject,NSCharacterEncodingDocumentAttribute: String.Encoding.utf8 as AnyObject
        ]
        do {
            let attributedString = try NSAttributedString(data: encodedData,options: attributedOptions,documentAttributes: nil) //Crash here
            return attributedString.string
        } catch {
            return self
        }
    }
    return self
}

但是在迅速的3中,它崩溃了

*** Terminating app due to uncaught exception
‘NSInvalidArgumentException’,reason: ‘-[_SwiftValue
unsignedIntegerValue]: unrecognized selector sent to instance
0x6080002565f0’

有人请建议我需要做什么?

解决方法

我遇到了同样的问题:

let attributedOptions : [String: AnyObject] = [
            NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType as AnyObject,NSCharacterEncodingDocumentAttribute: String.Encoding.utf8 as AnyObject
        ]

这里的String.Encoding.utf8类型检查失败.使用NSNumber(值:String.Encoding.utf8.rawValue)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读