每次运行时,XCode 都会编译整个项目 [英] XCode compiles entire project each time I run

查看:61
本文介绍了每次运行时,XCode 都会编译整个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我开始的一个新项目中,XCode 决定每次运行时都会编译项目中的每个文件,而不仅仅是编译更改的文件(以及依赖于这些文件的文件).随着项目中的文件越来越多,这在时间和电池寿命上都成为越来越大的负担.

On a new project I have started, XCode has decided that it will compile every file in the project every time I run it, rather than just compiling files that change (and files dependent on those). As there are getting to be more and more files in the project, this becomes a bigger and bigger burden in both time and battery life.

我可能在某处更改了影响此的设置;或者可能不是.我应该查看哪些项目设置?

It is possible that I have changed a setting somewhere that affected this; or, maybe not. What are some project settings that I should be looking at?

推荐答案

如果每次构建时 Xcode 都会重新编译大部分或全部源文件,这通常意味着这些文件都直接或间接依赖于某些头文件已经改变.以下是一些需要注意的事项:

If Xcode recompiles most or all of your source files whenever you do a build, that usually means that those files are all directly or indirectly dependent on some header file that has changed. Here are some things to look for:

  1. 你的源文件是否倾向于 #import 一些顶级头文件,这些头文件本身递归地导入一堆低级头文件?如果该依赖头文件树中的任何文件被修改,它将强制重新编译任何导入顶级头文件的 .m 文件.您可以通过为较低级别的子模块导入标头来减少这些依赖关系,或者更好的是,仅为每个文件所需的特定标头.(注意:有些库并非设计为以这种方式使用,在某些情况下可能会使这种方法具有挑战性或不可能.)

  1. Do your source files tend to #import some top-level header file that itself recursively imports a bunch of lower-level header files? If any file in that tree of dependent headers is modified, it will force recompilation of any .m file that imports the top-level header file. You may be able to reduce these dependencies by importing headers for lower level submodules, or better yet, for just the specific headers you need for each file. (Note: Some libraries that aren't designed to be used this way can make this approach challenging or impossible in some cases.)

某些第三方开发工具和静态库会运行脚本,在其构建过程中生成或修改代码.如果您的源文件依赖于由脚本生成的头文件,则每次脚本重新生成该头文件时都会重新编译它们.即使脚本生成的代码没有变化,如果头文件的最后修改日期发生变化,依赖的源文件也会被重新编译.如果这是您的问题,可能需要一些聪明的黑客来消除冗余编译.

Some third party development tools and static libraries run scripts that generate or modify code as part of their build process. If your source files are dependent on a header file that's generated by a script, they'll be recompiled every time the script regenerates that header file. Even if the code generated by the script doesn't change, dependent source files will be recompiled if the last-modified date of the header file changes. It may take some clever hacking to eliminate redundant compilation if this is your issue.

不要忘记检查您的预编译头 (.pch) 文件以查看正在导入的内容.该文件的内容在编译时有效地注入到项目中每个 .m 文件的顶部.

Don't forget to check your precompiled header (.pch) file to see what's being imported there. The contents of that file are effectively injected at the top of every .m file in your project at compile time.

通过将尽可能多的 #import 语句从 .h 文件移到 .m 文件中,尽量减少依赖性.您通常只需导入类的超类的头文件以及您的类在其 .h 文件中实现的任何协议即可.对于在类的 @interface 中使用的任何其他类、数据类型或协议,您可以使用前向声明而不是 #import 语句.

Try to minimize dependencies by moving as many #import statements as possible out of your .h files and into your .m files. You can generally get away with just importing the headers for your class's superclass and any protocols your class implements in its .h file. You can use forward declarations instead of #import statements for any other classes, data types, or protocols you use in your class's @interface.

这篇关于每次运行时,XCode 都会编译整个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆