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

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

问题描述

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

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< Cocoa / Cocoa.h>

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文件不在那里摆脱列表依赖。您仍应按照Xcode模板的要求导入 UIKit.h Foundation.h 。 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天全站免登陆