Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If two different Categories having same method, then which one will be invoked by Objective C runtime system?

Tags:

objective-c

If two different Categories having same method, then which one will be invoked by objective C runtime system ??

for example:

@interface ClassA (MathOps)
    -(void)CategoryMethod;
@end 

@interface ClassA (MathOps1)
-(void)CategoryMethod;
@end 

@implementation ClassA(MathOps1)
- (void) CategoryMethod{
    NSLog(@"Inside Category Method 2");
}
@end

@implementation ClassA(MathOps)
- (void) CategoryMethod{
    NSLog(@"Inside Category Method 1");
}
@end

Now if i am calling, [ObjClassA CategoryMethod];, Then which one called ? Why ?

like image 438
Matrix Avatar asked Sep 10 '10 16:09

Matrix


1 Answers

It's undefined. It depends on which category gets loaded first by the runtime, are there's no documented order in which that happens.

Bottom line: don't do this. :)

like image 64
Dave DeLong Avatar answered Sep 29 '22 01:09

Dave DeLong