Xcode 9.1 Swift 4, unable to compile with NSDocumentTypeDocumentAttribute if "if #available" is used

Use this line only:

cell.lblHeader.attributedText = try NSAttributedString(data: htmlData, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)

Seems like thats a correct syntax for Swift 4.1.2:

let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [
            NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html,
            NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue
        ]

Tags:

Ios

Xcode

Swift