Reputation: 1775
Say A is subclass of B
Say A has a category doThis.
B also has a category doThis.
Say I did
B* b = [[B alloc]init];
[b doThis];
Is there a guarantee that doThis declared in B+doThis.h will be the one called instead of A+doThis?
Sample:
in NSManagedObject+somecategories.m
+(void)vLoadBookmark
{
//Just empty
}
Latter
in BusinessObject+somecategories.m where BusinessObject is a subclass of NSManagedObject
+(void)vLoadBookmark
{
//Do something
}
If one day I called [someBusinessObject vLoadBookmark]
will //Do something be reached?
Upvotes: 1
Views: 84
Reputation: 63667
If a category overrides a method defined in another category, it is undefined what implementation will prevail.
From Apple's Programming with Objective-C > 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.
Upvotes: 5