views:

10

answers:

1

I'm trying to utilize a class from the Google Toolbox for Mac libraries, for unescaping HTML text. Specifically, I'm using GTMNSString+HTML.h and GTMNSString+HTML.m.

Where I'm trying to escape the text, I'm doing this:

NSString *escaped = [ gtm_stringByEscapingForHTML:_item.body ];

But when I try to compile I'm getting an error:

'gtm_stringByEscapingForHTML' undeclared (first use in this function)

I understand that this means I need to declare something earlier in my file, but I'm not sure where, and beyond that what the syntax would be.

Any help is greatly appreciated, thank you.

A: 

First, make sure you're including GTMNString+HTML.h in your implementation file.

#include "GTMNSString+HTML.h"

Second, that file defines a category on NSString, so it's methods become methods of NSString objects. You would invoke it like this:

// Assuming body is of type NSString *
NSString *escaped = [_item.body gtm_stringByEscapingForHTML];

You can learn more about categories here: https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCategories.html.

Robot K
Perfect! This solved my problem. Thank you so much. I'm still very new to Obj-C, so I'm going to have to look into Categories much more.
Dan Carson