IOS category name value

Can someone tell me the meaning of the category name when creating the category?

I know that the compiler uses this to identify and map implementations to interfaces. Is there any other use for this?

What if we create 2 categories with different names, implementing the same method in two 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 line

 NSString *goodString = @"GOOD"; 

I got the output [goodString isGood] as false.

I want to know why and how the category name is involved in this?

+5
source share
2 answers

As for category names, in accordance with this article, the only restriction is that they do not conflict with the names of other categories in the same class.

As for categories using the same method names, according to Apple Docs , it is undefined which method will be called at runtime.

+4
source

No matter which implementation of a method with the same name wins, it has nothing to do with category names. The β€œwinner” will be the one that was last loaded, and whichever it is, is not known until run time, because the order of loading is not deterministic.

0
source

Source: https://habr.com/ru/post/1209763/


All Articles