0

I have used the following code multiple times in the past and in one application it still compiles just fine:

let attrStr = try! NSAttributedString(data: myLabel.data(using: String.Encoding.unicode,allowLossyConversion: true)!, options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)

Now, I've started a new app and I get the following error:

Cannot convert value of type 'NSAttributedString.DocumentAttributeKey' to expected dictionary key type 'NSAttributedString.DocumentReadingOptionKey'

Can't seem to find anything that is applicable to fixing this, has something changed?

  • Possible duplicate of [Convert HTML to Plain Text in Swift](https://stackoverflow.com/questions/28124119/convert-html-to-plain-text-in-swift) – Larme Feb 25 '18 at 15:15
  • There is a change in Swift 4 and NSAttributedString in general (keys, values, etc.) – Larme Feb 25 '18 at 15:15
  • Then why doesn't the old code blow up? – Beth.larson1977 Feb 25 '18 at 15:22
  • I guess it's because you were still using Swift 3 in the previous app, but on the new one, you are using Swift 4 (default value for new projects)? – Larme Feb 26 '18 at 09:41

0 Answers0