开发者

iphone - compiler conditional on header

I have a project that generates applications for two targets.

One of the targets has to include one additional delegate protocol that should not be present on the other one. So, I have created a macro on Xcode and declared the header like this:

#ifdef TARGET_1
@interface myViewController : UIViewController <UIScrollViewDelegate, UIPopoverControllerDelegate>
#endif开发者_运维技巧

#ifdef TARGET_2
@interface myViewController : UIViewController <UIScrollViewDelegate>
#endif

{ .... bla bla.... }

The problem is that Xcode is hating this "double" declaration of @interface and is giving me all sort of errors. When I put just one of the declarations the errors vanish.

How to solve that? thanks for any help.


If you're getting a redecleration there you must have defined both symbols. Double check that your TARGET_1 and TARGET_2 defines aren't being defined together


I personally don't hesitate to write something like:

@interface myViewController : UIViewController <UIScrollViewDelegate
#ifdef TARGET_1
, UIPopoverControllerDelegate
#endif
>

It looks ugly, but I believe it better reflects the semantics.

You can even do one better:

#ifndef TARGET_1
@protocol UIPopoverControllerDelegate
@end
#endif

@interface myViewController : UIViewController <UIScrollViewDelegate, UIPopoverControllerDelegate>

All of this doesn't invalidate the previous answers of course!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜