I am getting a HTML Response from a webservice Below is the HTML I am getting in response
TopicGud mrng.
\\n
I would rather suggest to extend NSAttributedString with failable convenience init. String is not responsible for making NSAttributedString by it's nature.
extension NSAttributedString {
convenience init?(html: String) {
guard let data = html.data(using: String.Encoding.unicode, allowLossyConversion: false) else {
return nil
}
guard let attributedString = try? NSAttributedString(data: data, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil) else {
return nil
}
self.init(attributedString: attributedString)
}
}
label.attributedText = NSAttributedString(html: " Some bold and Hyperlink and so on ")