Scripted Classes
The syntax for creating a scripted class is very similar to the syntax for creating a class in Objective-C. The instances of a class created in such a manner behave like any other Objective-C object.To create a scripted class, you specify the class interface in an @interface...@end block and the class implementation in an @implementation...@end block. To ensure the class is loaded properly, 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; NSArray *employees; } @end @implementation Surfshop - (Surfshop *)initWithName:aName employees:theEmployees { name = [aName copy]; employees = [theEmployees retain]; return self; } @endDo not use separate files for the @interface and @implementation blocks. They must both be in the same file.
To use the class, you locate it in the application, load it, and then allocate and initialize instances using the class object. Here's an example:
NSMutableArray *allSurfshops; - init { id scriptPath; id surfshopClass; [super init]; scriptPath = [[[self application] resourceManager] pathForResourceNamed:@"Surfshop.wos" inFramework:nil]; surfshopClass = [[self application] 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; }
Table of Contents Next Section