0

I have a string which contains HTML entities, e.g. ’ which I want to show up as '. I'm pretty new to swift, so I am not sure how I can change all HTML entities since I can't seem to find an equivalent of GTMNSString+HTML for swift.

I tried to use the solution here: How do I decode HTML entities in swift?, but it is REALLY slow, i.e. it takes very long for the strings to be ready and my page to show. I also have problems using stringByReplacingOccurrencesOfString, since there are always errors e.g. missing ) or missing ,etc.

Any advice on how to proceed? Thanks!

Community
  • 1
  • 1
SilverHood
  • 713
  • 1
  • 8
  • 15
  • https://github.com/JigarM/Swift-Tutorials/tree/master/Swift-RSSFeed/Pods/MWFeedParser – Leo Dabus Dec 18 '14 at 03:46
  • @LeonardoSavioDabus This means that I will end up having extra stuff that I don't want. I will give tng's answer I try instead. Thank you!!! – SilverHood Dec 18 '14 at 04:00

1 Answers1

1

Why don't you try importing GTMNSString+HTML in your Swift bridging header and access this objective-c class/function from your Swift code? I would look here for a primer on how to do this: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

tng
  • 4,286
  • 5
  • 21
  • 30
  • I was thinking of doing that too. I will look into it as well. Thanks for the suggestion. Will accept your answer if I can get it done successfully =P – SilverHood Dec 18 '14 at 03:57
  • Let me know if you need help. It should be relatively straight forward to import the objective-c header into the bridging header and then using those functions from Swift. – tng Dec 18 '14 at 04:00
  • It seems so easy to add, but I can't use it =( I'm supposed to be able to use it normally right? – SilverHood Dec 18 '14 at 07:47
  • you should be able to just call .gtm_stringByEscapingForHTML(), like "hello".gtm_stringByEscapingForHTML() – tng Dec 18 '14 at 08:24
  • yea. I just figured that out. I just had to create a `NSString` first: `var testing:NSString` Thank you so much! – SilverHood Dec 18 '14 at 08:27