Swift-3错误:' - [_ SwiftValue unsignedIntegerValue]:无法识别的选择器 [英] Swift-3 error: '-[_SwiftValue unsignedIntegerValue]: unrecognized selector

查看:919
本文介绍了Swift-3错误:' - [_ SwiftValue unsignedIntegerValue]:无法识别的选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码与旧的swift完美配合。这是String的扩展名

Following code was perfectly worked with old swift. This is an extension of 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
}

但是在swift 3中它崩溃说

But in swift 3 it crashes saying


***由于未捕获的异常终止应用程序
'NSInvalidArgumentException',reason:' - [_ SwiftValue
unsignedIntegerValue]:无法识别s选民发送到实例
0x6080002565f0'

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

任何人都建议我需要做什么?

Anyone please suggest me what need to do?

推荐答案

我遇到同样的问题:

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

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

Here the String.Encoding.utf8 the type check fails. Use NSNumber(value: String.Encoding.utf8.rawValue)

这篇关于Swift-3错误:' - [_ SwiftValue unsignedIntegerValue]:无法识别的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆