Table of Contents Previous Section
Categories
A category is a set of methods you add to an existing class. You can add a category to any custom or WebObjects-provided Objective-C class. Because the methods added by the category become part of the class type, you can invoke them on any object of that type within an application. That is, you don't have to instantiate a special subclass.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)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:
- emailAddressOfSender {
NSString *address = [self headerForKey:@"From"];
if (!address) address = @"None";
return address;
}
@end
- takeValuesFromRequest:request inContext:context {Note: If your category is at the end of a scripted component, you must restart your app each time you change that file.
[super takeValuesFromRequest:request inContext:context];
[self logWithFormat:@"Email address of sender: %@",
[request emailAddressOfSender]];
}
Table of Contents Next Section