Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Objective-C, how to prevent name collision in category methods?

Tags:

objective-c

Some people have used prefixes to name their category methods in order to prevent possible name collisions with other external code, but I personally find that adding noise to a name that is otherwise clear. Is there a better way to avoid category name collisions than prefixing it?

e.g.

@interface UILabel (Extras)
-(void)prefix_extraMethod;
@end
like image 610
Boon Avatar asked Nov 30 '22 03:11

Boon


1 Answers

In Objective-C doesn't exist namespace so the only way is to prefix your method.

If don't want to prefix (I agree with you..it's ugly) you can the OBJC_PRINT_REPLACED_METHODS environment variable to YES to receive a warning if you method name collide with other existing method.

set environment variable

like image 85
Luca Bernardi Avatar answered Dec 24 '22 20:12

Luca Bernardi