The difference between a class method
and an instance method
is that an
instance method requires an instance of the class on which it will
(generally) operate. The message to invoke an instance method must be
sent to an instance of a class.
For example
In Cocoa the NSString class has several class methods named
stringWithSomethingOrOther: that will create a new NSString object and
hand it back to you.
On the other hand, NSString also has many instance methods -
operations which really have no meaning without an actual instance to
work with. A commonly-used one might be the length method, which tells
you how many characters are in the specific NSString instance to which
the message is sent.
Suppose for another example-
@interface DeepsClass : NSObject
+ (void)myClassMethod;
- (void)myInstanceMethod;
@end
It can now be used like this : -
[DeepsClass myClassMethod];
DeepsClass *object = [[DeepsClass alloc] init];
[object myInstanceMethod];
Performance difference
Performance is almost the same
in class methods & instance methods. Class methods are treated at runtime like any other methods (eg. instance methods), and while the Class may be loaded at runtime, the methods themselves are C functions, same as instance methods, and the POINTERS to those functions are cached, just like instance methods.