Disabling *No visible @interface* error for unit t

2019-09-19 11:38发布

问题:

I have a category (on NSDate) that contains a method that is only called from another method within the category, so there is no need to expose the method in the category's header file.

However, as expected, if I call the method from a unit test, the compiler shouts that

No visible @interface for 'NSDate' declares the selector 'myMethod:'

I'd like to be able to turn off these particular errors (for the unit test target only, of course).

Can someone point me in the direction of the correct compiler flag?

回答1:

Instead of turning them off why not just redeclare it? If you turn the warnings off completely then you lose the fact that the compiler will give you warnings in genuine places.

So just declare it above the unit test

@interface NSDate (UnitTests)

// your method sig

@end

@implementation YourUnitTest

//...