NSString *myString = @"This is my string."; - (NSString *)appendString:(NSString *)aString { NSString *returnString = [NSString stringWithFormat:@"%@ %@", myString, aString]; return returnString; }Explicitly specifying a class in a variable or method declaration is called static typing.
Because variables and return values are always objects, the only supported data types are classes. You can specify any class that your application recognizes when you statically type a variable or a method. For example, each component in your application is a class, so you can do this:
CarPage *carPage = [[self application] pageWithName:"CarPage"];Also, the default application executable used to run your application contains the definitions of classes from the Foundation, WebObjects, and Enterprise Objects frameworks, so these declarations are valid:
NSString *myString; //Foundation classes WOContext *theContext; //WebObjects classes EOEditingContext *editingContext; //Enterprise Objects classesPlus, if you're writing a component that uses database access, your application has an EOModel file that translates tables in your database into objects. You can specify any entity named in that model file as a class. For example:
Movies *moviesEntity; //entities from your eomodelStatic typing is supported so that WebObjects Builder can correctly parse your script file and help you decide which variables you can correctly bind to certain dynamic elements. (For more information on this, see the online book WebObjects Tools and Techniques.) As far as WebScript is concerned, all variables are of type id.
Note: WebObjects performs absolutely no type checking. The following is valid WebScript:
NSNumber *aNumber = @"Wait! I'm a string, not a number!"; NSString *aString = 1 + 2;
Table of Contents Next Section