views:

31

answers:

2

I have a project with several targets. For most of my classes, I can use a single .h file and change the details in the .m file (adding a different .m file for each target).

For one of my UIViewController subclasses, I need to declare different UILabel IBOutlets for the different targets (each target shows a different set of labels depending on what's available). The problem is that header files can't be targeted. There's no checkbox next to them to specify target membership.

The way I've been dealing with this is to just add outlets for all of the targets and ignore the unused ones. It doesn't seem ideal.

Do I need to use a header build phase for this? What's the best way to deal with this problem? Thanks.

Edit: I should have mentioned that I want all the .h files to have the same name: PlaceViewController.h.

+1  A: 

Headers don't get compiled themselves, but are included in other files which are then compiled. You can use conditional compilation inside those files to include the correct headers for the target. Define a unique symbol in the preprocessor symbols for each target, and include the appropriate headers accordingly:

#if defined(TARGET_ONE)
#include "HeaderOne.h"
#elif defined(TARGET_TWO)
#include "HeaderTwo.h"
#endif
Jason Foreman
Sorry, I should have said that I want all my headers to have the same name. I edited my question above.
nevan
The only way to do that is to put the headers in subdirectories, then alter your search paths for each target to include the correct subdirectory. Down that way lies madness though. I highly recommend not doing whatever it is you're trying to do and figuring out a better way. Separate files (with unique names) per target is probably a good place to start.
Jason Foreman
+1  A: 

You can use preprocessor directives to selectively include the header files. For instance

#if TARGET_OS
   #import "FirstTarget.h"
#else
   #import "SecondTarget.h"
#endif

You can use different folders for different targets if the headers are the named the same:

#if TARGET_OS
   #import "First/Target.h"
#else
   #import "Second/Target.h"
#endif

You can read more about conditionals here.

Shaji
Sorry, I should have said that I want the headers to have the same name.
nevan
@nevan I have updated the answer.
Shaji