Xcode - 基于Target导入具有相同名称的不同头文件
我有一个具有多个目标的项目,每个目标都构建非常相似的应用程序版本,但具有不同的图像资源和 plist。对于 plists/images 来说这很好,但我使用 ShareKit 和 Appirater 框架,它们的配置带有 #defines 的头文件。对于每个版本,我认为需要导入此头文件的不同版本,因为每个目标构建的每个应用程序的配置都不同。
所以目标A有SHConfig.h 并且目标 B 有一个不同的 SHConfig.h
我可以编辑这些框架的源代码以根据目标导入不同的标头,但是当我升级框架时这会很混乱。
有没有更好的方法根据目标导入不同的头文件(具有相同的名称)?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设它们位于不同的目录中,请在每个目标中设置标头搜索路径以将正确的目录放在第一位。
您可能想将其设置为类似
$(SRCROOT)/foo:$(HEADER_SEARCH_PATHS)
的内容,但我不确定这是否有必要。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.我发现有用的是将公共目录名称放在标头搜索路径中,然后使用不同的#import。我的目录结构是 Common/Views/v1 和 Common/Views/v2。我想要 v1 用于一个目标,而 v2 用于另一个目标。
就我而言,我在标题搜索路径中使用的搜索路径是:
然后,我使用:
在需要第二个版本的目标中(这会找到 $(SRCROOT)/../Common/Views/v2/ActivityIndicator.h)。
奇怪的是,另一个目标(我创建的第一个目标)没有指定完整路径就可以了。即,
可以找到 $(SRCROOT)/../Common/Views/v1/ActivityIndicator.h
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:
Then, I used:
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.,
works to find $(SRCROOT)/../Common/Views/v1/ActivityIndicator.h
以下过程为我解决了问题
选择特定目标
在“构建阶段”下 -->添加“新标题阶段”-->展开“标题”-->单击添加(加号)并-->浏览到要添加的特定于目标的文件。 (它将在“项目”部分下添加文件)。
对其他目标重复该过程。
在 Xcode 10.2 上测试
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