第三方库如何在 Objective-C 和 Xcode 中工作?

发布于 2024-12-02 10:51:22 字数 459 浏览 3 评论 0原文

Objective-C 和 Xcode 还很新(2 周),我正在尝试添加我的第一个“外部”库,即 restkit ,从外部服务器读取一些 JSON。

然而,看看他们的“入门”指南,据我了解,您只需下载一个包含源代码的包并将其链接起来,并将其构建为您自己构建的一部分...... (指南在这里),特别是第4点很有趣)

我是多年的 Java 开发人员和我尝试将它与它在那里的工作方式进行比较,其中包含无法更改的已编译、打包的 jar 文件。 jarfiles 与此有何关系?据我所知,您可以直接进入并更改您认为合适的任何第三方文件。

如果有人能帮助我理解这一点,我将不胜感激。

Pretty new (2 weeks) into Objective-C and Xcode, and I'm trying to add my first "external" library, namey restkit, to read some JSON from an external server.

However, looking at their "getting started" guide, from what I understand you just download a package with the sourcecode and link it in and build it as part of your own build somehow...
(the guide is here), expecially point 4 is interesting)

I am a many-years Java developer and I try to compare it to how it works there, with compiled, packaged jar-files that you can't alter. How do jarfiles relate to this? From what I can see, you can just go in and change any of the third-party files as you see fit.

If someone could help me grasp this I'd appreciate it.

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

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

发布评论

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

评论(4

只怪假的太真实 2024-12-09 10:51:22

外部代码可以是:

动态库(.dlyb),它可以作为框架分发并安装在计算机上。但请注意,您无法在 iPhone 上安装框架 - 您的应用程序是沙盒的。您可以使用一系列适用于所有 iPhone 的框架。

您还可以使用静态库。静态库在链接期间编译到您的应用程序二进制文件中。

链接:
http://blog.carbon Five.com/2011 /04/04/using-open-source-static-libraries-in-xcode-4/

另一种相当常见的形式是使用代码。这在 iPhone 开发中很常见,因为它的封闭性该设备是并且您的应用程序的沙盒程度如何。它也很受欢迎,因为许多组件和库都是在 github 上开源的。共享代码通常有两种形式:

复制代码 - 将一些文件添加到您的应用程序中即可。您必须定期更新文件。

xcode 子项目 - 您可以将外部库 xcode 项目作为子项目添加到您的项目中。该子项目可以生成您的应用程序使用的静态库(目标)。在xcode4中,您还可以拥有一个包含多个项目的工作区。

使用代码的好处是能够对其进行调试。代码越复杂,使用子项目就越有吸引力。如果它是一些独立的文件,那么只需添加这些文件就很简单。

希望对一些人有帮助。

external code can be:

a dynamic library (.dlyb) which can be distributed as a framework and installed on the machine. But be aware, that you can't install frameworks on the iPhone - your app is sandboxed. A set number of frameworks are available to you which are on all iPhones.

you can also consume a static library. a static library is compiled into your apps binary during linking.

links:
http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/

The other and fairly common form is consuming code. It's common in iPhone development because how closed the device is and how sandboxed your app is. it's also popular because many components and libraries are open sourced on github. sharing code usually comes in two forms:

copy code - add some files to your app and off you go. you have to update files on some perioding basis.

xcode sub-project - you can add an external libraries xcode project as a sub-project to your project. that sub-project can produce a static library (target) which your app consumes. in xcode4, you can also have a workspace which contains multiple projects.

Consuming code has the benefit of being able to debug into it. The more complex the code becomes, the more attractive consuming a sub-project is. If it's a handful of self-contained files, then just adding the files is simple.

hope that helps some.

云雾 2024-12-09 10:51:22

第三方框架可以采用源代码形式,也可以作为编译框架。已编译的框架可能最接近您习惯的 jar 文件。在这种情况下,框架可作为源代码使用,因此他们建议将框架项目添加到您的项目中。

我更喜欢单独编译我​​的框架,然后将编译后的框架包含在我的项目中。无论哪种方式都有效。

Third party frameworks can come in source form, or as a compiled framework. A compiled framework is probably closest to a jar-file that you're used to. In this case, the framework is available as source code, so they suggest adding the framework project to your project.

I prefer to compile my frameworks separately, and just include the compiled framework in my projects. Either way works.

暗地喜欢 2024-12-09 10:51:22

另一种方法是名为 CocoaPods 的依赖管理器。它仍处于测试阶段,但已可以使用。对于某些库,有一些配方,如果您没有找到所需的,您可以创建一个其规范。 RestKit 的规范可用。

An another way is a dependency manager called CocoaPods. It is still beta, but it is ready to use. There are a few recipes for some libraries and if you don't find that you want, you can create a specification for it. A specification for RestKit is available.

岁月打碎记忆 2024-12-09 10:51:22

你为什么这么难受!选择您的项目并进入构建阶段>编译源>在此处添加您添加的 .m 文件 >构建并运行>享受

why you taking this too hard ! select your project and go to build phase > compile sources > add you .m file here which you added > build and run > Enjoy

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