views:

131

answers:

2

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.

+1  A: 

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

Joshua Weinberg
thanks! see my coment to KennyTM... amazing.
Digital Robot
+1  A: 

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!

Jean-Denis Muys
thanks! I learn new things every day with SO's gurus!!!!!
Digital Robot