I am doing an extension to convert html to attribute string, code
extension String { var htmlToAttributedString: NSAttributedString? { guard let data = data(using: .utf8) else { return nil } do { return try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil) } catch let error as NSError { print(error.localizedDescription) return nil } } var html2String: String { return htmlToAttributedString?.string ?? "" }
I get the following 3 identical errors
Using the unresolved identifier 'NSDocumentTypeDocumentAttribute'
Using the unresolved identifier 'NSHTMLTextDocumentType'
Using an Unresolved Identifier 'NSCharacterEncodingDocumentAttribute'
I assume that I made a mistake with the syntax to cause 3 of the same error, but I could not understand what else the extension would need.
thanks
source share