Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在编译期间有条件地包含协议?_Iphone_Objective C - Fatal编程技术网

Iphone 如何在编译期间有条件地包含协议?

Iphone 如何在编译期间有条件地包含协议?,iphone,objective-c,Iphone,Objective C,是否可以有条件地包括协议?例如,下面是一些不起作用的代码,但应该可以让您了解我指的是什么。我只希望在打开广告时包含界面 // this works fine #if ADS_SUPPORTED #import "AdWhirlView.h" #endif // this does NOT work @interface MyAppDelegate : NSObject <UIApplicationDelegate #if ADS_SUPPORTED ,AdWhirlDelegate #e

是否可以有条件地包括协议?例如,下面是一些不起作用的代码,但应该可以让您了解我指的是什么。我只希望在打开广告时包含界面

// this works fine
#if ADS_SUPPORTED
#import "AdWhirlView.h"
#endif

// this does NOT work
@interface MyAppDelegate : NSObject <UIApplicationDelegate #if ADS_SUPPORTED ,AdWhirlDelegate #endif>
//这很好用
#如果支持的话
#导入“adwirlview.h”
#恩迪夫
//这行不通
@接口MyAppDelegate:NSObject
您可以执行以下操作:

#if ADS_SUPPORTED
@interface MyAppDelegate : NSObject <UIApplicationDelegate,AdWhirlDelegate>
#else
@interface MyAppDelegate : NSObject <UIApplicationDelegate>
#endif
#如果支持广告#
@接口MyAppDelegate:NSObject
#否则
@接口MyAppDelegate:NSObject
#恩迪夫
…但是IB可能会有点困惑。请参阅,它提供了一种替代方案。

这行不通

重复接口声明两次,一次使用协议,另一次不在#if/#else/#endif结构中阻塞

预处理器指令只能以非嵌套方式工作,就像您的头include一样