Xcode:复制标头:公共、私有、项目?

发布于 2024-12-04 17:47:45 字数 56 浏览 1 评论 0原文

我正在构建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑梦风尘 2024-12-11 17:47:45

公开:界面已最终确定,供您产品的客户使用。公共标头作为可读源代码包含在产品中,不受限制。

私有:该界面不适合您的客户,或者处于开发的早期阶段。产品中包含私有标头,但它被标记为“私有”。因此,这些符号对所有客户端都是可见的,但客户端应该明白他们不应该使用它们。

项目:该接口仅供当前项目中的实现文件使用。项目标头不包含在目标中,目标代码除外。这些符号对客户根本不可见,只有您自己可见。

来源: Xcode 开发者库>工具与语言> IDE >项目编辑器帮助>设置头文件的可见性

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.

Source: Xcode Developer Library > Tools & Languages > IDEs > Project Editor Help > Setting the Visibility of a Header File

当爱已成负担 2024-12-11 17:47:45

兰迪的回答很好,为您提供了所有相关背景。我想添加一些信息来根据您期望的图书馆使用方式为您提供帮助。

项目:如果您要分发项目,并希望用户将您的项目作为子项目包含在自己的项目中,则应确保标头标记为“项目”。不这样做会导致以下问题:
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).

朮生 2024-12-11 17:47:45

Objective-C 头文件:公共、私有、项目

[Objective-C 静态库手册]< br>
[目标会员资格]

公共 - 向消费者

私有 - API向消费者公开,但使用它是有风险的

项目 - API对消费者不可见。模块级别的一种封装

文件结构

ClassA.h - public
ClassB.h - project
ClassC.h - private

Headers 文件夹设置为:

Public Headers Folder Path(PUBLIC_HEADERS_FOLDER_PATH)
//default value is
$(CONTENTS_FOLDER_PATH)/Headers

PrivateHeaders 文件夹设置为:

Private Headers Folder Path(PRIVATE_HEADERS_FOLDER_PATH)
//default value is
$(CONTENTS_FOLDER_PATH)/PrivateHeaders

1.暴露 Objective-C 代码对于 Objective-C 或 Swift 使用者,您应该使用 .modulemappublic 标头

//Swift
import SomeModule

//Objective-C
@import SomeModule;

[.modulemap] ->仅公共标头或错误

要以非模块使用方式向 Objective-C 使用者公开 Objective-C 代码

//Objective-C

//umbrella
#import <ObjCFramework/ObjCFramework.h>

//specific руфвук
#import <ObjCFramework/ClassA.h>
//#import <ObjCFramework/ClassB.h> //error
#import <ObjCFramework/ClassC.h>

2.当您导入项目标头时,

Showing All Messages
'ObjCFramework/ClassB.h' file not found

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

ClassA.h - public
ClassB.h - project
ClassC.h - private

Headers folder is set by:

Public Headers Folder Path(PUBLIC_HEADERS_FOLDER_PATH)
//default value is
$(CONTENTS_FOLDER_PATH)/Headers

PrivateHeaders folder is set by:

Private Headers Folder Path(PRIVATE_HEADERS_FOLDER_PATH)
//default value is
$(CONTENTS_FOLDER_PATH)/PrivateHeaders

1.To expose Objective-C code for Objective-C or Swift consumers you should use .modulemap and public headers

//Swift
import SomeModule

//Objective-C
@import SomeModule;

[.modulemap] -> only public headers or error

2.To expose Objective-C code for Objective-C consumer with non-module usage

//Objective-C

//umbrella
#import <ObjCFramework/ObjCFramework.h>

//specific руфвук
#import <ObjCFramework/ClassA.h>
//#import <ObjCFramework/ClassB.h> //error
#import <ObjCFramework/ClassC.h>

when you import a project header you get

Showing All Messages
'ObjCFramework/ClassB.h' file not found
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文