Xcode:复制标头:公共、私有、项目?
我正在构建一个 Cocoa Touch 静态库。我应该如何决定是否将头文件复制为公共、私有或项目?
I'm building a Cocoa Touch Static Library. How should I decide whether to copy a header file as public, private, or project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来源: Xcode 开发者库>工具与语言> IDE >项目编辑器帮助>设置头文件的可见性
Source: Xcode Developer Library > Tools & Languages > IDEs > Project Editor Help > Setting the Visibility of a Header File
兰迪的回答很好,为您提供了所有相关背景。我想添加一些信息来根据您期望的图书馆使用方式为您提供帮助。
项目:如果您要分发项目,并希望用户将您的项目作为子项目包含在自己的项目中,则应确保标头标记为“项目”。不这样做会导致以下问题:
Xcode 4 Archive Version Unspecified
请注意,这适用于每个子项目...包括子项目的子项目,递归。
公共:如果您希望库的用户仅链接到您的对象(并且没有您的原始项目),请确保您的标头标记为“公共”(仅适用于他们需要的标头)参考)。
Randy's answer is good and gives you all the relevant background. I wanted to add some info to help you based on how you expect your library will be used.
PROJECT: If you are distributing your project, and expect users to include your project as a sub-project in their own, you should ensure your headers are marked as 'project'. Not doing so will lead to issues like this:
Xcode 4 Archive Version Unspecified
Note that this applies to every sub-project...including sub-projects of sub-projects, recursively.
PUBLIC: If you expect users of your library to only link against your object (and NOT have your original project), make sure your headers are marked as 'public' (only for headers they'll need to refer to).
Objective-C 头文件:公共、私有、项目
[Objective-C 静态库手册]< br>
[目标会员资格]
公共 - 向消费者
私有 - API向消费者公开,但使用它是有风险的
项目 - API对消费者不可见。模块级别的一种封装
文件结构
Headers 文件夹设置为:
PrivateHeaders 文件夹设置为:
1.暴露 Objective-C 代码对于 Objective-C 或 Swift 使用者,您应该使用
.modulemap
和 public 标头[.modulemap] ->仅公共标头或错误
要以非模块使用方式向 Objective-C 使用者公开 Objective-C 代码
2.当您导入项目标头时,
Objective-C Headers: Public, Private, Project
[Objective-C static library manual]
[Target Membership]
public - API which is exposed for consumer
private - API which is exposed for consumer but it is risky to use it
project - API is not visible for consumer. A kind of encapsulation on module level
File structure
Headers folder is set by:
PrivateHeaders folder is set by:
1.To expose Objective-C code for Objective-C or Swift consumers you should use
.modulemap
and public headers[.modulemap] -> only public headers or error
2.To expose Objective-C code for Objective-C consumer with non-module usage
when you import a project header you get