Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - Importing different header file with same name based on Target

I have a project with multiple targets each of which builds a pretty similar versions of the app but with different images assets and plists. For plists/images that's fine but I use the ShareKit and Appirater frameworks which have header files with #defines for their config. For each version I believe need to import a different version of this header file, as the config is different for each app built by each target.

So target A has SHConfig.h and target B has a DIFFERENT SHConfig.h

I could edit the source for these frameworks to import different headers based on the target but that'd be messy when I come to upgrade the frameworks.

Is there a better way to import different header files (with the same name) based on the target?

like image 902
NeilInglis Avatar asked Feb 01 '11 22:02

NeilInglis


2 Answers

Assuming they're in different directories, set the Header Search Paths in each target to put the correct directory first.

You may want to set it to something like $(SRCROOT)/foo:$(HEADER_SEARCH_PATHS), though I'm not sure whether that's necessary.

like image 125
Peter Hosey Avatar answered Oct 22 '22 19:10

Peter Hosey


What I found useful was to put the Common directory name in the header search path, and then to use a different #import. My directory structure was Common/Views/v1 and Common/Views/v2. I wanted the v1 for one target and the v2 for another.

In my case, the search path I used in Header Search Paths was:

$(SRCROOT)/../Common/

Then, I used:

#import <Views/v2/ActivityIndicator.h>

In the target that needed the second version (this finds $(SRCROOT)/../Common/Views/v2/ActivityIndicator.h).

Oddly, the other target (the first one I created) is fine without specifying the full path. I.e.,

#import "ActivityIndicator.h"

works to find $(SRCROOT)/../Common/Views/v1/ActivityIndicator.h

like image 27
Chris Prince Avatar answered Oct 22 '22 20:10

Chris Prince