Table of Contents
Previous Section
You can create an Objective-C class in a script file, then load that class into your application at run time and generate instances from it. The instances will behave as any other Objective-C object.
As with categories, no typing is permitted. You must specify the class interface in an @interface...@end block and the class implementation in an @implementation...@end block. For the sake of loading, the scripted class code should be in its own ".wos" file. The following example is in a file named Surfshop.wos:
@interface Surfshop:NSObject {
id name;
id employees;
}
@end
@implementation Surfshop
- initWithName:aName employees:theEmployees {
name = [aName copy];
employees = [theEmployees retain];
return self;
}
@end
To use the class, you locate it in the application, load it, and then allocate and initialize instances using the class object. For example:
id allSurfshops;
- init
{
id scriptPath;
id surfshopClass;
[super init];
scriptPath = [WOApp pathForResourceNamed:@"Surfshop" ofType:@"wos"];
surfshopClass = [WOApp scriptedClassWithPath:scriptPath];
allSurfshops = [NSMutableArray array];
[allSurfshops addObject:[[[surfshopClass alloc] initWithName:
"Banana Surfshop" employees:@("John Popp", "Jenna de Rosnay")] autorelease]];
[allSurfshops addObject:[[[surfshopClass alloc] initWithName:
"Rad Swell" employees:@("Robby Naish", "Nathalie Simon")] autorelease]];
return self;
}