Error NSAttributedString when switching to Swift 3

1

I have this code used to convert this type of characters: simbólica to this: simbólica .

do {
      let encodedData = actualLabel.text!.data(using: String.Encoding.utf8)!
      let attributedOptions: [String: AnyObject] = [
          NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType as AnyObject,
          NSCharacterEncodingDocumentAttribute: String.Encoding.utf8 as AnyObject
      ]
      let attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil)
          actualLabel.text = attributedString.string
} catch {
   fatalError("Unhandled error: \(error)")
}

In swift 2.0 worked correctly. But in swift 3 it returns this error to me and it does not let me continue with the execution of the app.

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

Doing the debug, I have reached the line where it gives an error, which is concretely:

let attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil)
    
asked by 21.09.2016 в 09:45
source

1 answer

0

You can use like

let attributedString = try NSAttributedString(data: encodedData, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil)
    
answered by 21.09.2016 / 15:45
source