Search code examples
iosobjective-cobjective-c-category

The priority between two Categories


I have two Categories(c1 and c2) for a Class, they both has the same method -(void)run when I send message to this method,why the responder always be the c2 Category? I think they should have the same priority.


Solution

  • Methods in class categories are added to the class in the order in which they are found. A method with the same name (selector) as an existing method will simply replace the earlier implementation with that of the newly-found method.

    There are no guarantees on the order in which categories will be processed, so never rely on it.