Using the following code migrated from swift3 to swift4,
let options: [NSAttributedString.DocumentReadingOptionKey: AnyHashable] =
[.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue]
let str = try NSAttributedString( data:string!.data(using: String.Encoding.utf8, allowLossyConversion: true
)!, options:options, documentAttributes: nil)
iOS 9+ has no problem, when running iOS 8.3, console output: "dyld: Symbol not found: _NSCharacterEncodingDocumentOption"; It would be passed after commented ".characterEncoding: String.Encoding.utf8.rawValue".