第三方库如何在 Objective-C 和 Xcode 中工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7250302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do third-party libraries work in Objective-C and Xcode?
提问by Mathias
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.
Objective-C 和 Xcode 相当新(2 周),我正在尝试添加我的第一个“外部”库,即restkit,以从外部服务器读取一些 JSON。
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)
但是,查看他们的“入门”指南,据我所知,您只需下载一个包含源代码的包并将其链接并以某种方式将其构建为您自己构建的一部分......(指南在这里),特别是第 4 点很有趣)
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.
我是一名多年的 Java 开发人员,我尝试将它与它在那里的工作方式进行比较,其中包含您无法更改的已编译、打包的 jar 文件。jarfile 与此有何关系?据我所知,您可以根据需要更改任何第三方文件。
If someone could help me grasp this I'd appreciate it.
如果有人能帮助我理解这一点,我将不胜感激。
回答by bryanmac
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.
一个动态库 (.dlyb),可以作为框架分发并安装在机器上。但请注意,您无法在 iPhone 上安装框架 - 您的应用程序已被沙盒化。您可以使用一定数量的框架,这些框架适用于所有 iPhone。
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/
链接: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:
另一种相当常见的形式是使用代码。这在 iPhone 开发中很常见,因为设备的封闭程度以及您的应用程序的沙箱程度。它也很受欢迎,因为许多组件和库都是在 github 上开源的。共享代码通常有两种形式:
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.
xcode 子项目- 您可以将外部库 xcode 项目作为子项目添加到您的项目中。该子项目可以生成您的应用程序使用的静态库(目标)。在 xcode4 中,您还可以拥有一个包含多个项目的工作区。
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.
希望能帮到一些人。
回答by Flyingdiver
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.
第三方框架可以是源代码形式,也可以是编译后的框架。编译后的框架可能最接近您习惯的 jar 文件。在这种情况下,该框架可作为源代码使用,因此他们建议将框架项目添加到您的项目中。
I prefer to compile my frameworks separately, and just include the compiled framework in my projects. Either way works.
我更喜欢单独编译我的框架,并且只在我的项目中包含编译后的框架。无论哪种方式都有效。
回答by Lukas Kubanek
An another way is a dependency manager called CocoaPods. It is still beta, but it is ready to use. There are a fewrecipes 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.
另一种方法是使用名为CocoaPods的依赖项管理器。它仍然是测试版,但已经可以使用了。有少数一些图书馆配方和,如果你没有找到你想要的,你可以为它创建一个规范。RestKit 的规范是可用的。
回答by Bijendra singh bhatia
why you taking this too hard ! select your project file and select build phase > compile sources > add you .m file here which you addded > build and run > Enjoy
为什么你太难了!选择您的项目文件并选择构建阶段 > 编译源代码 > 在此处添加您添加的 .m 文件 > 构建并运行 > 享受