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? 
            Asked
            
        
        
            Active
            
        
            Viewed 532 times
        
    0
            
            
         
    
    
        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 Answers
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
- 
                    Thanks, but this code gives "Declaration is only valid at file scope" error :( – johncoffey Feb 14 '15 at 11:27
- 
                    Just put ir at the bottom of your file or add another file (swift source file) and put it there. – Leo Dabus Feb 14 '15 at 13:25