Sending a Message to a Class
Usually, the object receiving a message is an instance of a class. For example, in this statement the variable aString is an instance of the class NSString:
[aString length];You can also send messages to a class. You send a class a message when you want to create a new instance of that class. For example this statement tells the class NSString to invoke its stringWithString: method, which returns an instance of NSString that contains the specified string:
aString = [NSString stringWithString:@"Fred"];Note that a class is represented in a script by its corresponding class name-in this example, NSString.
In WebScript, the classes you use include both class methods and instance methods. Most class methods create a new instance of that class, whereas instance methods provide behavior for instances of the class. In the following example, a class method, stringWithFormat:, is used to create an instance of a class, NSString. Instance methods are then used to operate on the instance myString:
// Use a class method to create an instance of NSString NSString *myString = [NSString stringWithFormat:@"The next word is %@", word]; // Use instance methods to operate on the instance myString length = [myString length]; lcString = [myString lowercaseString];In an Objective-C class definition, class methods are preceded by a plus sign (+), while instance methods are preceded by a minus sign (-). You cannot declare class methods in WebScript, but you can use the Objective-C class methods defined for any class.
Table of Contents Next Section