I get the answer (string) from the server ( json ) with html markup.
Example:
<p> sometext </p> How to get clean text?
Create an extension for the class String Thus:
extension String { var html2AttributedString: NSAttributedString? { guard let data = dataUsingEncoding(NSUTF8StringEncoding) else { return nil } do { return try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute:NSUTF8StringEncoding], documentAttributes: nil) } catch let error as NSError { print(error.localizedDescription) return nil } } var html2String: String { return html2AttributedString?.string ?? "" } }
and use this property for the line you need.
var someString = "<p> sometext </p>" someString.html2String Good luck.
Source: https://ru.stackoverflow.com/questions/560581/
All Articles