理解 Xcode 的 Copy Headers 阶段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10584936/
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
Understanding Xcode's Copy Headers phase
提问by Danra
In Xcode's "Copy Headers" phase, what is the difference between the headers under the "Project" section and the "Private" section? When would you want to use each?
在Xcode的“Copy Headers”阶段,“Project”部分和“Private”部分下的headers有什么区别?你想什么时候使用每一个?
Also, I can understand why you would want to copy public headers (for a static library for instance) - but why would you want to copy private headers?
另外,我可以理解您为什么要复制公共标头(例如对于静态库)-但是为什么要复制私有标头?
Edit:@mipadi below explains the roles of the Public and Private parts. However I'm still missing the difference between including a header in the "Project" part vs. not having the header in any part of the "Copy Headers" phase.
编辑:@mipadi 下面解释了 Public 和 Private 部分的作用。但是,我仍然缺少在“项目”部分包含标题与在“复制标题”阶段的任何部分都没有标题之间的区别。
采纳答案by mipadi
If a public header includes a private header, you have to copy the private headers, but you want to make sure that consumers of the library or framework know that those private headers are not part of the public API.
如果公共标头包含私有标头,则必须复制私有标头,但要确保库或框架的使用者知道这些私有标头不是公共 API 的一部分。
"Project" headers are private headers that are notincluded by a public header (they're usually part of the internal implementation and thus only included in an implementation -- .c
or .m
-- file).
“项目”标头是不包含在公共标头中的私有标头(它们通常是内部实现的一部分,因此仅包含在实现 --.c
或.m
-- 文件中)。
When building a framework, public headers are copied into the Headers
directory of the framework, whereas private headers are copied into the PrivateHeaders
directory.
在构建框架时,公共头文件被复制到Headers
框架的目录中,而私有头文件被复制到PrivateHeaders
目录中。
回答by user2532301
@Danra, if you put your headers under "Project", those headers will be visible to your implementations 'regardless' of the actual location of the headers.
@Danra,如果您将标题放在“项目”下,那么这些标题将对您的实现可见,而不管标题的实际位置如何。
Let's say, you have your folder structure like this: /Sources/libAF/AFSomething.h /Sources/libAF/AFSomething.m /Sources/exec/main.m
假设您的文件夹结构如下: /Sources/libAF/AFSomething.h /Sources/libAF/AFSomething.m /Sources/exec/main.m
If you've put 'AFSomething.h' under "Project", you can use it in main.m like this: #import "AFSomething.h"
如果你把 'AFSomething.h' 放在“Project”下,你可以在 main.m 中像这样使用它:#import "AFSomething.h"
In layman's term, Xcode will include Project headers though you omit actual path info.
通俗地说,Xcode 将包含项目标头,尽管您省略了实际路径信息。
回答by Adrian Sluyters
Just to add to this, usually people have a script to 'clean' the Private Headers so that the public canon no way see what the symbols are. For debug/development purposes leave the private headers be, they come in handy at the development and debug stages.
只是为了补充一点,通常人们有一个脚本来“清理”私有标题,这样公众就无法看到符号是什么。对于调试/开发目的,保留私有头文件,它们在开发和调试阶段派上用场。
回答by Andrew Schleifer
From Setting the Visibility of a Header File:
Public: The interface is finalized and meant to be used by your product's clients. A public header is included in the product as readable source code without restriction.
Private: The interface isn't intended for your clients or it's in early stages of development. A private header is included in the product, but it's marked “private”. Thus the symbols are visible to all clients, but clients should understand that they're not supposed to use them.
Project: The interface is for use only by implementation files in the current project. A project header is not included in the target, except in object code. The symbols are not visible to clients at all, only to you.
公共:接口已完成,旨在供您产品的客户使用。产品中包含一个公共头文件作为可读的源代码,没有限制。
私有:该界面不是为您的客户设计的,或者它处于开发的早期阶段。产品中包含私有标题,但标记为“私有”。因此这些符号对所有客户都是可见的,但客户应该明白他们不应该使用它们。
项目:该接口仅供当前项目中的实现文件使用。项目标头不包含在目标中,目标代码中除外。客户根本看不到这些符号,只有您才能看到。