I have two categories defined for the same class and have same function but different definition. I want to choose a particular function of a category at runtime on some condition.
Does obj c compiler maintain some book keeping for categories.
I was thinking in terms of C++ (virtual function/Vtable) where these can be achieved using polymorphism. How can I solve such scenario in objective C.
Class MyClass;
File:Myclass+category1.h
@interface MyClass (CategoryOne)
-(void) printCategory()
@end
File:Myclass+category2.h
@interface MyClass (CategoryTwo)
-(void) printCategory()
@end
Now I included both the header files in MyClass.m. Is there any possibility of liberty of choosing the particular definition of “printCategory()” at some runtime condition?
No. If two categories implement the same method, it is undefined which one is executed.
From the docs: