I have a category "NSObject+completeOnce". And I use it for main app, watch, widget. But I haven't added it into watch and widget target. Of course I must do it.
My Question is:"Why I don't see any warnings or linking errors in this case? Can I force them?" I have more than 100 classes in my project and sometimes do such mitakes :( It would be good to find some way to check it before runnig.
Category declaration:
//Category is added only into main target.
@interface NSObject (completeOnce)
+ (void)completeBlockOnce:(void(^)(void))block forKey:(NSString*)key
@end
Usage:
@implementation SomeOtherClass
+ (void)method
{
//It crashes for for widgets.
//And Here is no any warnings. Also no linking errors at all
[NSObject completeBlockOnce:^{
//Some Code
} forKey:@"FixMigrationBug_1_0_to_1_6"];
}
@end
I am sure that I have only one declaration of this method. And I have to emphasize that it is the same problem for all categories. Even for categoryes of my custom classes with 99% unique method name.
What you're seeing is a compound issue. You're right in looking for two types of errors -- compiler warnings/errors, and linker errors. You're not getting either, for two reasons:
These two things combined lead to the behavior you're seeing. The only way to be sure that these methods don't exist is to simply try to call them at runtime -- where now, you're getting an exception (if uncaught, leads to a crash), since they have not actually been included in the app binary.