Can anyone please tell me the significance of category name when we create a category?
I know that the compiler uses this to identify and match the implementations with interfaces. Is there any other use for it?
What if we create 2 categories with different names implementing same method in 2 different ways. Example:
@interface NSString(Good)
- (BOOL)isGood;
@end
@implementation NSString(Good)
- (BOOL)isGood
{
return TRUE;
}
@end
@interface NSString(Bad)
- (BOOL)isGood;
@end
@implementation NSString(Bad)
- (BOOL)isGood
{
return FALSE;
}
@end
And now in the program I create a string
NSString *goodString = @"GOOD";
I got the output of [goodString isGood]
as false.
I want to know why and how the name of category is involved in this?
With respect to the category names, according to this article the only restriction is that they don't conflict with other category names within the same class.
With respect to the categories using the same method names, according to the Apple Docs, it's undefined which method will be called at runtime.
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