Please explain class methods
        Posted  
        
            by 
                user1209902
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user1209902
        
        
        
        Published on 2012-06-03T22:29:20Z
        Indexed on 
            2012/06/03
            22:40 UTC
        
        
        Read the original article
        Hit count: 230
        
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
© Stack Overflow or respective owner