Say that Apple has an API defined in a private header file:
// Can't see this at all
@interface NSThing
- (void)secretMethod;
@end
and I have a category:
@interface NSThing (Helpers)
- (void)secretMethod;
@end
Does this override Apple's implementation and will their other private methods start calling into my implementation?
From "Avoid Category Method Name Clashes":
If the name of a method declared in a category is the same as a method in the original class, or a method in another category on the same class (or even a superclass), the behavior is undefined as to which method implementation is used at runtime. This is less likely to be an issue if you’re using categories with your own classes, but can cause problems when using categories to add methods to standard Cocoa or Cocoa Touch classes.
So if you "accidentally" implement a category method with the same name as an existing method (private or not), the behaviour is undefined.
You should therefore prefix your category methods with a prefix that makes name clashes unlikely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With