5

我目前正在研究一个NSProxy子类,它拦截某些消息并且从不将它们转发给任何人,而只是处理它们,所以这些方法永远不会真正存在。问题来了,显然编译器开始抱怨缺少方法实现,我不知道如何停止它,向接口添加存根方法只是为了让编译器关闭是行不通的,因为方法是任意形成的,我不知道它们(为了使其更具体,我要求这个项目)。

理想情况下,我想告诉编译器它根本不应该对这个特定的类进行任何方法检查,但由于这似乎不太可能,我也会为一种#pragma或任何其他方式感到高兴(其中不包括关闭为整个项目/文件中的每个警告编译器!)

4

1 回答 1

1

Your switch statements aren't really arbitrary, they just could have an arbitrary length. For a broad number of lengths, you could go ahead and declare them for the benefit of the compiler (and you'd then get error checking, which you wouldn't if you just turned off the warning). For example:

typedef void (^ObjCCaseBlock)();

@interface NSObject ()
- (id)switch;
- (void)case:(NSString*)a :(ObjCCaseBlock)b;
- (void)case:(NSString*)a :(ObjCCaseBlock)b case:(NSString*)a :(ObjCCaseBlock)b;
- (void)case:(NSString*)a :(ObjCCaseBlock)b case:(NSString*)a :(ObjCCaseBlock)b case:(NSString*)a :(ObjCCaseBlock)b;
@end

Repeat for as many levels as is likely to occur (and you could add levels if it ever bumped into a problem). It's a little bit tedious, but not difficult.

于 2012-03-14T19:25:16.363 回答