Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
While you can execute a class method with just the name of the class, you need an object to be able to execute object methods—and object methods are more useful because class methods have restrictions on how they store data that object methods don’t. You define an object method in a class by preceding its prototype and definition with a minus sign, “-”, in both the @interface section and @implementation section, as shown here, where we create an object method named stringValue that returns a string:
@interface ClassWithMethod : NSObject
- (const char *) stringValue;
@end
@implementation ClassWithMethod
- (const char *) stringValue;
{
return "Hello there.";
}
@end