Table of Contents
Previous Section
To create a category, you must implement it within an @implementation block, which is terminated by the @end directive. Place the category name in parentheses after the class name.
The following example is a simple category of WORequest that gets the sender's Internet e-mail address from the request headers ("From" key) and returns it (or "None").
@implementation WORequest(RequestUtilities)
- emailAddressOfSender {
NSString *address = [self headerForKey:@"From"];
if (!address) address = @"None";
return address;
}
@end
Elsewhere in your WebScript code, you invoke this method on WORequest objects just as you do with any other method of that class. Here's an example:
- takeValuesFromRequest:request inContext:context {
[super takeValuesFromRequest:request inContext:context];
[self logWithFormat:@"Email address of sender: %@",
[request emailAddressOfSender]];
}
The category must be included either at the end of a component's script file (that is, a script file within a .wo) or it must be included in a scripted class's stand-alone script file. Do not place categories in the application or session script.
Table of Contents
Next Section