Sunday, June 19, 2011

Categories in obj-c

// Base Class
@interface ClassA : NSObject
- (NSString *) myMethod;
@end
@implementation ClassA
- (NSString*) myMethod { return @"A"; }
@end

//Category
@interface ClassA (CategoryB)
- (NSString *) myMethod;
@end
@implementation ClassA (CategoryB)
- (NSString*) myMethod { return @"B"; }
@end



Calling the method "myMethod" after including the category nets the result "B".

No comments:

FEEDJIT Live