Orkhan Alizade
Orkhan Alizade

Reputation: 7549

HTML inside of textView

I want to paste HTML text(with p, br, bgcolor etc.) inside of textView. I did try the next:

var bodyText = NSAttributedString(data: body.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil, error: nil)

postBody.text = bodyText

postBody -> textView. But it prints the next error:

Cannot assign a value of type 'NSAttributedString?' to a value of type 'String!'

How can I correctly print it inside of textView?

Upvotes: 0

Views: 1421

Answers (1)

Léo Natan
Léo Natan

Reputation: 57040

Instead of text, use attributedText.

postBody.attributedText = bodyText

Or, if you just want the text without the attributes, use NSAttributedString's string property.

postBody.text = bodyText?.string

Upvotes: 6

Related Questions