0

I have an RSS feed and in its description element (here: www.marketoloji.com/?feed=rss2) I have ascii characters for the ones like ' or & and they are seen as ’ / &. How can I render that description string in Swift so that I wont see ascii characters?

johncoffey
  • 251
  • 3
  • 12
  • I hate to break it to you, but pretty much every character you see on this screen (with the exception of that single quote) is ASCII. – Hot Licks Feb 14 '15 at 02:40
  • @HotLicks: as you see, i am beginner when it comes to naming the character types :) but i hope you got my point, i simply want to show `'` and `&' instead of `’` and `&` in my app when i render this text. should i check every character manually or is there an easy way to make this happen in swift? – johncoffey Feb 14 '15 at 02:47

1 Answers1

0

You can use NSAttributedString to easily convert html code for you using the NSHTMLTextDocumentType option:

extension String {
    var htmlString:String {
        return NSAttributedString(data: dataUsingEncoding(NSUTF8StringEncoding)!, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding], documentAttributes: nil, error: nil)!.string
    }
}


let htmlCode = "’ / &"

htmlCode.htmlString  // "’ / &"
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571