Question: I'm finding it difficult to understand when it is necessary to create class methods. From what I've read, they are important for creating new objects, but I do not see how. The following class create a simple shape black rectangle. Can anyone show me how to incorporate a class method to do something that I could not do with an instance method?

Shape.h

```
#import <UIKit/UIKit.h>
@interface Shape : UIView; 
- (id) initWithX: (int)xVal andY: (int)yVal;
@end

```

Shape.m

```
#import "Shape.h"
@implementation Shape 
- (id) initWithX:(int )xVal andY:(int)yVal {
self = [super init];    
UIView *shape = [[UIView alloc] initWithFrame:CGRectMake(xVal, yVal, 10, 10)];
shape.backgroundColor = [UIColor blackColor];
[self addSubview:shape];
return self;
}
@end

```

Answer: 
Class methods are simply methods that don't need objects. Therefore, any instance method that doesn't use its object could be a class method. The only time you must use a class method is when a method must be called without an object. `alloc` is a good example: it creates the object and returns it, so by definition there is no object when it is called.

One other use I've had for class methods (in C++ in embedded systems, so I don't have code to show) is to have a class keep a doubly-linked list of all its objects. (This is useful for debugging dumps; in embedded development your debugging tools are often just some kind of `printf`.)

The class has two members which are pointers to the first and last elements of the list, and the constructor and destructor insert and remove an object from the list. The functions to access the first and last objects are class methods, since you call those when you want to traverse the list of objects but don't have an object yet.
My answer would be that class methods are very useful when you need to do some utility functions / methods and *don't* need to be doing actions on some specific instance or object. 

For example, in my own code, I typically do class methods in classes where the outcome will be the same no matter which object I could possibly call the method on. Like:

E.G. 

```
@interface MyAppCacheFiles
    + (NSURL *) getFileURLOfLocalCache;
@end

```

These could also be considered convenience methods (e.g. much like `NSString +stringWithFormat:` or `NSArray +arrayWithArray:`).