Possible Duplicate:
What happens if two ObjC categories override the same method?
I have two Categories on NSString class as follows:
//first category
#import "NSString+MyCategory1.h"
@implementation NSString (MyCategory1)
-(void)myMethod{
NSLog(@"this is my method from category 1");
}
@end
//second category
#import "NSString+MyCategory2.h"
@implementation NSString (MyCategory2)
-(void)myMethod{
NSLog(@"this is my method from category 2");
}
@end
But the following main method is always calling myMethod
from MyCategory1
even after import of the same has been commented out.
#import <Foundation/Foundation.h>
//#import "NSString+MyCategory1.h"
#import "NSString+MyCategory2.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
[[[NSString alloc]init] myMethod];
}
return 0;
}
Please anyone explain this behavior and how this behavior is useful in practice.