Xcode - 在自定义配置中排除文件 - 更好的方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2270202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode - exclude files in a custom configuration - better way?
提问by Sean Clark Hess
I'm trying to come up with a way to make it easy to switch out our "mock" data services and our live ones. Basically, we'll have live servers with real web services, but for whatever reason, a developer may want to load data from static files (file urls).
我正在尝试想出一种方法来轻松切换我们的“模拟”数据服务和我们的实时数据服务。基本上,我们将拥有具有真实 Web 服务的实时服务器,但无论出于何种原因,开发人员可能希望从静态文件(文件 url)加载数据。
I figured I would solve this problem by creating categories that override the methods that fetch the data, thus leaving original code untouched (it has no concept of the "mock" data). I don't want to litter my code with #ifdef
.
我想我可以通过创建覆盖获取数据的方法的类别来解决这个问题,从而保持原始代码不变(它没有“模拟”数据的概念)。我不想用#ifdef
.
I can put an #ifdef at the very beginning of each file that has categories in it, and I can set a custom flag in the configuration settings, but I'd rather just have a way to include or exclude the files depending on the configuration. Is that possible? How do you solve this problem?
我可以在每个包含类别的文件的开头放置一个 #ifdef,并且我可以在配置设置中设置一个自定义标志,但我宁愿有一种根据配置包含或排除文件的方法. 那可能吗?你怎么解决这个问题?
回答by cdespinosa
See http://lists.apple.com/archives/xcode-users/2009/Jun/msg00153.html
见http://lists.apple.com/archives/xcode-users/2009/Jun/msg00153.html
The trick is to define EXCLUDED_SOURCE_FILE_NAMES in the configuration you want to exclude the files from, and set the value of that custom build setting to a list of the file names (or a pattern that matches those, and only those, file names).
诀窍是在要从中排除文件的配置中定义 EXCLUDED_SOURCE_FILE_NAMES,并将该自定义构建设置的值设置为文件名列表(或与这些文件名匹配的模式,并且仅匹配那些文件名)。
回答by TechZen
I would recommend creating two targets one of which has the mock categories included and another one which does not.
我建议创建两个目标,其中一个包含模拟类别,另一个不包含。
When you want to test, just build the target containing the mock categories. Everything else can remain identical.
当您要测试时,只需构建包含模拟类别的目标即可。其他一切都可以保持相同。
回答by doozMen
If you would like to add a file but do not wont to compile it. Go to (for all your targets) project>build phases>compile source and take out the file that you do not want to compile.
如果您想添加一个文件但不想编译它。转到(对于所有目标)项目>构建阶段>编译源并取出您不想编译的文件。