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

≯℡__Kan透↙ 提交于 2019-11-30 05:27:39

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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!