如何共享/分发已编译的 Objective-C 代码(如 Java 中的 JAR)?

发布于 2024-07-26 08:52:20 字数 298 浏览 6 评论 0原文

我想编写一些用于分发的 Objective-C 代码。 打包输出的最佳方法是什么? 在 Java 中,您可以将代码打包到 JAR 文件中并分发它。 Objective-C 中的等价物是什么?

以下链接很接近,但似乎解决了更多我不关心的命名空间问题。 我最关心的是设置代码以便于分发。

Objective-C 相当于 Java 包?

I would like to write some Objective-C code for distribution. What is the best way to package up the output. In Java you can package up your code in a JAR file and distribute that. What would be the equivalent in Objective-C?

The following link is close, but seems to address more of the namespace issues which I am not concerned about. I am mostly concerned about setting the code up for easy distribution.

Objective-C equivalent of Java packages?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

萌化 2024-08-02 08:52:20

框架几乎肯定是一条出路。 OS X 上的框架的真正好处之一是它们可以将可执行代码、标头、元数据、图像、图标等捆绑在一个包中。 此外,框架可以包含在 */Library/Frameworks/ 中,甚至可以包含在应用程序包中,以完全脱离任何其他应用程序对给定版本框架的依赖。

Apple 的框架编程指南< /strong> 是开始使用框架的最佳位置。

创建框架很简单。 基本上,在 Xcode 中,您选择“File”>“File”。 New Project... 并选择 Framework,然后选择 Cocoa Framework。 这将设置一个具有框架目标的新项目,并在构建时自动为您打包所有内容。

不要忘记文档和单元测试是一件好事™,特别是对于框架而言,它本质上比大多数最终用户代码更有可能被多个客户端使用。 您可以向框架 Xcode 项目添加更多目标来记录和测试它。

既然您正在寻找示例,请查看 CHDataStructures.framework (我开发的一个项目)和 PSMTabBarControl.framework (其中包括框架中的许多额外资源)。 两者都是开源的,并且应该为您自己的开发提供足够的示例。

一句建议可以让您免去一些麻烦:除非您单击框架目标并将角色更改为“公共”(或“私有”),否则您的头文件将不会复制到构建的框架中)。

A framework is almost certainly the way to go. One of the really nice things about Frameworks on OS X is that they can bundle the executable code, headers, metadata, images, icons, etc. in a single package. Further, frameworks can be included in */Library/Frameworks/ or even inside your app bundle to completely decouple from any other app's dependency on a given version of the framework.

Apple's Framework Programming Guide is the best place to get started with frameworks.

Creating a framework is simple. Basically, in Xcode you choose File > New Project... and select Framework, then Cocoa Framework. This will set up a new project with framework target and automatically package everything up for you when you build.

Don't forget that documentation and unit tests are a Good Thing™, especially for frameworks, which are inherently more likely to be used by multiple clients than most end-user code. You can add more targets to your framework Xcode project to document and test it.

Since you're looking for examples, check out CHDataStructures.framework (a project which I develop) and PSMTabBarControl.framework (which includes lots of extra resources in the framework). Both are open-source, and should provide adequate examples for rolling your own.

One word of advice to save you some head-scratching: your header files will not be copied to the built framework unless you click on the framework target and change the Role to "Public" (or "Private").

阳光的暖冬 2024-08-02 08:52:20

您想要创建一个框架。 Xcode 中有一个新项目的起点来创建其中之一。 虽然有一些注意事项和陷阱,但总的来说,整个过程很简单。

编辑:澄清一下:如果您计划将其作为 FOSS 分发; 将其打包在一个框架中可能有点过分; 仅仅分发源代码可能是一个更明智和更简单的选择。 但是,如果您想保留源代码或将其与相关资源集合一起分发,那么框架绝对是一个好主意。

重新编辑:有关介绍,请参阅 http://developer.apple.com/documentation/ MacOSX/概念/BPFrameworks/

You want to create a Framework. There is a starting point in Xcode for a new project to create one of these. There are a few caveats and gotchas, but on the whole the process is straightforward.

Edit: For clarification: If you are planning to distribute it as FOSS; packing it up in a framework might be overkill; just distributing the source code might be a more sensible and simpler option. But if you would like to keep the source to yourself or distribute it with a collection of relevant resources, a framework might definitely be a good idea.

Reedit: For an introduction, see http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/

风吹过旳痕迹 2024-08-02 08:52:20

你没有说它是否适用于 iPhone。 在 iPhone 上,它需要是一个 .sa(静态链接库)——但我认为正态分布应该是 .dylib 或 .so

You didn't say if it was for iPhone or not. On the iPhone, it needs to be a .sa (statically linked library) -- but I think the normal distribution would by a .dylib or .so

伴梦长久 2024-08-02 08:52:20

您可以将其编译为框架或静态库(.so我相信)。

You could compile it as a Framework or as a static library (.so I believe).

柳若烟 2024-08-02 08:52:20

Java 程序在虚拟机上下文中运行。 Jar 包含抽象字节码,VM 必须将其转换为本机机器代码。

Objective-C 与 C 一样,被编译为本机机器代码,例如 Win .exe 文件,可直接由操作系统运行。

大多数任何复杂程度的程序都包含多个文件,包括 DLL、图标文件等。用于分发的文件配置通常由安装实用程序处理。

Java programs run in the context of a virtual machine. Jar contains abstract bytecodes which must be converted into native machine code by the VM.

Objective-C, like C, is compiled into native machine code, such as a Win .exe file, directly runnable by the operating system.

Most programs of any complexity consist of more than a single file and include DLLs, icon files, etc. The configuration of your files for distribution would usually be handled by a setup utility.

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