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

时间:2023-01-13 00:06:23

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?

我想写一些Objective-C代码进行分发。打包输出的最佳方法是什么?在Java中,您可以将代码打包在JAR文件中并进行分发。 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?

Objective-C相当于Java包?

5 个解决方案

#1


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.

框架几乎肯定是要走的路。关于OS X上的Frameworks的一个非常好的事情是它们可以将可执行代码,标题,元数据,图像,图标等捆绑在一个包中。此外,框架可以包含在* / Library / Frameworks /中,甚至可以包含在应用程序包中,以完全脱离任何其他应用程序对给定版本框架的依赖性。

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

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

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.

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

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.

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

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.

由于您正在寻找示例,请查看CHDataStructures.framework(我开发的项目)和PSMTabBarControl.framework(包括框架中的大量额外资源)。两者都是开源的,应该提供足够的例子来推销自己的。

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").

一个建议就是为您节省一些麻烦:除非您单击框架目标并将角色更改为“公共”(或“私有”),否则您的头文件将不会复制到构建的框架。

#2


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.

您想要创建一个框架。 Xcode中有一个起点,用于创建其中一个新项目。有一些警告和陷阱,但总的来说这个过程很简单。

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.

编辑:澄清:如果您打算将其作为FOSS分发;将其打包在一个框架中可能会有点过分;只是分发源代码可能是一个更明智和更简单的选择。但是,如果您想将源代码保留给自己或者将其与一组相关资源一起分发,那么框架肯定是个好主意。

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

Reedit:有关介绍,请参阅http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/

#3


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

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

#4


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

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

#5


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.

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

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

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

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.

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

#1


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.

框架几乎肯定是要走的路。关于OS X上的Frameworks的一个非常好的事情是它们可以将可执行代码,标题,元数据,图像,图标等捆绑在一个包中。此外,框架可以包含在* / Library / Frameworks /中,甚至可以包含在应用程序包中,以完全脱离任何其他应用程序对给定版本框架的依赖性。

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

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

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.

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

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.

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

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.

由于您正在寻找示例,请查看CHDataStructures.framework(我开发的项目)和PSMTabBarControl.framework(包括框架中的大量额外资源)。两者都是开源的,应该提供足够的例子来推销自己的。

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").

一个建议就是为您节省一些麻烦:除非您单击框架目标并将角色更改为“公共”(或“私有”),否则您的头文件将不会复制到构建的框架。

#2


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.

您想要创建一个框架。 Xcode中有一个起点,用于创建其中一个新项目。有一些警告和陷阱,但总的来说这个过程很简单。

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.

编辑:澄清:如果您打算将其作为FOSS分发;将其打包在一个框架中可能会有点过分;只是分发源代码可能是一个更明智和更简单的选择。但是,如果您想将源代码保留给自己或者将其与一组相关资源一起分发,那么框架肯定是个好主意。

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

Reedit:有关介绍,请参阅http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/

#3


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

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

#4


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

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

#5


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.

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

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

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

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.

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