为什么在 Xcode 6 中没有自动创建 ProjectName-Prefix.pch? [英] Why isn't ProjectName-Prefix.pch created automatically in Xcode 6?

查看:26
本文介绍了为什么在 Xcode 6 中没有自动创建 ProjectName-Prefix.pch?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 ProjectName-Prefix.pch 不是在 Xcode 6 中自动创建的?

Why isn't ProjectName-Prefix.pch created automatically in Xcode 6 ?

不再需要预编译头了吗?

Is the precompile header no longer needed ?

我应该在哪里写ProjectName-Prefix.pch之前的代码?

Where should I write the code that was in ProjectName-Prefix.pch before ?

推荐答案

我怀疑是因为模块,这消除了对 #import 的需要.

I suspect because of modules, which remove the need for the #import <Cocoa/Cocoa.h>.

至于在什么地方放置你应该放在前缀头中的代码,没有任何代码你应该放在前缀头中.将您的导入放入需要它们的文件中.将您的定义放入它们自己的文件中.把你的宏......无处可去.停止编写宏,除非别无他法(例如当您需要 __FILE__ 时).如果您确实需要宏,请将它们放在标题中并包含在内.

As to where to put code that you would put in a prefix header, there is no code you should put in a prefix header. Put your imports into the files that need them. Put your definitions into their own files. Put your macros...nowhere. Stop writing macros unless there is no other way (such as when you need __FILE__). If you do need macros, put them in a header and include it.

前缀标头对于整个系统中几乎所有东西都使用的巨大事物是必需的(例如Foundation.h).如果您拥有如此庞大且无处不在的东西,您应该重新考虑您的架构.前缀头使代码重用变得困难,如果列出的任何文件可以更改,则会引入微妙的构建问题.避免使用它们,直到您遇到严重的构建时间问题,您可以证明使用前缀标头可以显着改善.

The prefix header was necessary for things that are huge and used by nearly everything in the whole system (like Foundation.h). If you have something that huge and ubiquitous, you should rethink your architecture. Prefix headers make code reuse hard, and introduce subtle build problems if any of the files listed can change. Avoid them until you have a serious build time problem that you can demonstrate is dramatically improved with a prefix header.

在这种情况下,您可以创建一个并将其传递给 clang,但这是一个好主意的情况非常罕见.

In that case you can create one and pass it into clang, but it's incredibly rare that it's a good idea.

对于您在所有视图控制器中使用的 HUD 的具体问题,是的,您绝对应该将其导入到实际使用它的每个视图控制器中.这使得依赖关系清晰.当你在一个新项目中重用你的视图控制器(如果你很好地构建了你的控制器,这很常见),你会立即知道它需要什么.这对于类别尤其很重要,如果它们是隐式的,这会使代码很难重用.

To your specific question about a HUD you use in all your view controllers, yes, you should absolutely import it into every view controller that actually uses it. This makes the dependencies clear. When you reuse your view controller in a new project (which is common if you build your controllers well), you will immediately know what it requires. This is especially important for categories, which can make code very hard to reuse if they're implicit.

PCH 文件不是用来摆脱列表依赖的.您仍然应该根据需要导入 UIKit.hFoundation.h,就像 Xcode 模板所做的那样.使用 PCH 的原因是在处理非常庞大的标头(如 UIKit)时缩短构建时间.

The PCH file isn't there to get rid of listing dependencies. You should still import UIKit.h or Foundation.h as needed, as the Xcode templates do. The reason for the PCH is to improve build times when dealing with really massive headers (like in UIKit).

这篇关于为什么在 Xcode 6 中没有自动创建 ProjectName-Prefix.pch?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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