Error in swift NSAttributedString

0

I have migrated to Swift 4 but I have the following error that I can not solve:

  

Cannont convert value of type '[String: AnyObject]' to expected aegument type '[NSAttributedString.DocumentReadingOptionKey: Any]'

let encodedData = label.text!.data(using: String.Encoding.utf8)!
let attributedOptions: [String: AnyObject] = [
    NSAttributedString.DocumentAttributeKey.documentType.rawValue: NSAttributedString.DocumentType.html as AnyObject,
    NSAttributedString.DocumentAttributeKey.characterEncoding.rawValue: String.Encoding.utf8.rawValue as AnyObject
]
let attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil)
label.text = attributedString.string

The error appears here:

let attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil)

In the variable: attributedOptions

    
asked by Alberto Mier 22.12.2017 в 10:20
source

1 answer

1

In a Playground this compiles

let attributedOptions: [NSAttributedString.DocumentReadingOptionKey: Any] = [
    .documentType : NSAttributedString.DocumentType.html,
    .characterEncoding: String.Encoding.utf8.rawValue
]
    
answered by 10.01.2018 в 22:44