Tutorial :How can I use different .h files for several targets?



Question:

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.


Solution:1

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

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





        
Previous
Next Post »