禁止编译 Xcode 项目中的某些文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12600762/
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
Disabling some files in Xcode project from compilation
提问by Murat ?gat
I have started a new project in Xcode by duplicating an existing folder, because my new app will have a lot of common features with the old one.
我通过复制现有文件夹在 Xcode 中启动了一个新项目,因为我的新应用程序将具有许多与旧应用程序相同的功能。
The problem is that the new app won't be using a framework I used in the old app. When I deleted the framework, of course all files including that framework raised errors.
问题是新应用程序不会使用我在旧应用程序中使用的框架。当我删除框架时,当然包括该框架在内的所有文件都会引发错误。
Basically I want to disable all syntax checks, dependency checks, etc. on many files. I want Xcode to ignore these files, although they are in the project tree. Later when I revise them I will manually enable them again. This way I can compile and test my small changes for errors without fixing all errors it causes in the "not revised" files, which I will be fixing in the future anyway.
基本上我想禁用许多文件的所有语法检查、依赖性检查等。我希望 Xcode 忽略这些文件,尽管它们在项目树中。稍后当我修改它们时,我将再次手动启用它们。通过这种方式,我可以编译和测试我的小更改是否有错误,而无需修复它在“未修订”文件中引起的所有错误,无论如何我将在将来修复这些错误。
I could delete them from the project tree and then add them again one by one when my job's done, but I don't want to do this because my project tree might get messed up and there should really be another way to accomplish this.
我可以将它们从项目树中删除,然后在我的工作完成后重新添加它们,但我不想这样做,因为我的项目树可能会搞砸,而且真的应该有另一种方法来实现这一点。
I tried removing those files from all target memberships, but it didn't help.
我尝试从所有目标成员资格中删除这些文件,但没有帮助。
回答by newah
If you need to remove a lot of files, you could create User-Defined Build Setting which should be called EXCLUDED_SOURCE_FILE_NAMES. And add file names or patterns.
如果您需要删除大量文件,您可以创建用户定义的构建设置,该设置应称为 EXCLUDED_SOURCE_FILE_NAMES。并添加文件名或模式。
In my case I selected the target I wanted to omit some files, Editor -> Add Build Setting -> Add User-Defined Setting (at first this is greyed out somehow. I selected the project file (just above TARGETS) then reselected target file and was able to create User-Defined Setting) -> name it EXCLUDED_SOURCE_FILE_NAMES -> value something like PREFIX*
在我的例子中,我选择了我想省略一些文件的目标,编辑器 -> 添加构建设置 -> 添加用户定义的设置(起初这以某种方式变灰。我选择了项目文件(就在 TARGETS 上方)然后重新选择了目标文件并且能够创建用户定义的设置)-> 将其命名为 EXCLUDED_SOURCE_FILE_NAMES -> 值类似于 PREFIX*
Of course you can create User-Defined Setting for whole project that way all targets will have it.
当然,您可以为整个项目创建用户定义的设置,这样所有目标都将拥有它。
Example how it may look:
例如它的外观:
Original answer: http://lists.apple.com/archives/xcode-users/2009/Jun/msg00153.html
原答案:http: //lists.apple.com/archives/xcode-users/2009/Jun/msg00153.html
回答by Stefan Vasiljevic
In Xcode 9, I am not sure about older versions, go to:
在 Xcode 9 中,我不确定旧版本,请转到:
Build Settings -> Build Options -> Excluded Source File Names
构建设置 -> 构建选项 -> 排除的源文件名
Add all file names you want excluded. You can even do wildcard matching.
添加要排除的所有文件名。您甚至可以进行通配符匹配。
Bellow is an example of how I have excluded all files starting with dev-
and ending with .cc
for all schemes except for a Debug scheme that is built for Simulator. All Debug Simulator builds exclude files starting with release-
and ending with .cc
Bellow 是我如何排除所有方案的所有文件开头dev-
和结尾的示例,.cc
除了为模拟器构建的调试方案。所有调试模拟器构建排除文件开头release-
和结尾.cc
Hope this helps!!
希望这可以帮助!!
UPDATE
更新
I had a similar problem with frameworks and you can exclude frameworks from being embedded into your app with this too!
我在框架方面遇到了类似的问题,您也可以使用此功能将框架从嵌入到您的应用程序中排除!
My problem was that I had 2 frameworks, one was built for the simulator and the other was build for ARM. iTunes Connect complained about me including the simulator one with the app.
我的问题是我有 2 个框架,一个是为模拟器构建的,另一个是为 ARM 构建的。iTunes Connect 抱怨我在应用程序中包含了模拟器。
If you have many frameworks this help with reducing the app's size too.
如果您有许多框架,这也有助于减小应用程序的大小。
回答by Des
Check out the answer here
在这里查看答案
Xcode: Is there a location/flag to prevent a Class from compiling?
In a nutshell remove the file(s) from the project target.
简而言之,从项目目标中删除文件。
回答by aknew
As dirty hack you can try exclude not files, but its code by using #ifdef NotCompile + #endif
as it's done in C\C++ with .h with adding\removing #define NotCompile
in YOURPROJECT-prefix.pch
作为肮脏的黑客,您可以尝试排除不是文件,而是使用#ifdef NotCompile + #endif
它的代码,就像在 C\C++ 中使用 .h 所做的那样,#define NotCompile
在 YOURPROJECT-prefix.pch 中添加\删除