2

In Swift4.1 and Xcode 9.3.1 I am getting error

Type 'String' has no member 'documentType'

do {
        let modifiedFont = NSString(format:"<span style=\"font-family: '-apple-system', 'HelveticaNeue'; font-size: 16\">%@</span>" as NSString, string) as String

        let data = modifiedFont.data(using: String.Encoding.utf8, allowLossyConversion: true)
        if let d = data {

            let str = try NSAttributedString(data: d,
                                             options: [.documentType : NSAttributedString.DocumentType.html],
                                             documentAttributes: nil)
            return str
        }
    } 

Like This

niravdesai21
  • 4,818
  • 3
  • 22
  • 33

1 Answers1

1

This solution worked for me.

 do {
        let modifiedFont = NSString(format:"<span style=\"font-family: '-apple-system', 'HelveticaNeue'; font-size: 16\">%@</span>" as NSString, string) as String

        let data = modifiedFont.data(using: String.Encoding.utf8, allowLossyConversion: true)
        if let d = data {
            let str = try NSAttributedString(data: d,
                                             options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
            return str
        }
    } catch {
    }
niravdesai21
  • 4,818
  • 3
  • 22
  • 33