5

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?

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

4 Comments

For two files to have the same name, they HAVE to be in different directories.
Thanks Peter, works well. An alternative that was suggested was to create my own "master" SHKConfig.h and define #ifdefs in that to pass off to other files. This has minimal overhead and less reliance on the build tools. Both solutions seem to work.
I did exactly that and it doesn't work. I have one target that looks for the header in the other target's folder. Any idea what i'm doing wrong?
@Rafa: Make sure you're using the correct build setting (there are several related to search paths), and that you're specifying the needed directory's path correctly (particularly tricky if it's in a build product; e.g., if the other target builds a framework). Note that naming a specific file within the search path does not work: All of the paths must refer to directories.
1

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

Comments

0

Following process solved the issue for me

Select specific target Under "Build Phases" --> add "New Headers Phase" --> Expand "Headers" --> click on add(plus symbol) and --> browse to the file to be added specific for the target. (It will add file under 'project' section).

Repeat the process for other targets. Tested on Xcode 10.2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.