简体   繁体   English

iOS Framework构建:与第三方库链接的最佳实践是什么?

[英]iOS Framework build: what is the best practice to link with third-party libraries?

I'm build a Framework for iOS and my framework has AFNetworking as dependency. 我正在构建一个iOS框架,我的框架将AFNetworking作为依赖。 So what is the best practice to include AFNetworing? 那么包含AFNetworing的最佳做法是什么? Reading other posts (specially this question here ) i came up with three options: 阅读其他职位(特别是这个问题, 在这里 ),我想出了三个选项:

  1. Copy all the .hm files from AFNetworing in to my project and compile my framework with it. 将AFNetworing中的所有.hm文件复制到我的项目中,并使用它编译我的框架。 But according to this , it will possible cause a situation where some third part developer using my Framework are already using AFNetworking and will get a compile-time error that some class is declared twice. 但是根据这一点 ,可能会导致使用我的框架的某些第三方开发人员已经在使用AFNetworking并且将获得编译时错误,某些类被声明两次。

  2. Use CocoaPods and link AFNetworking to my Framework. 使用CocoaPods并将AFNetworking链接到我的框架。 This is causing this error: -lPods is not an object file (not allowed in a library) . 这导致此错误: -lPods不是目标文件(库中不允许)

  3. Build something like the Aeris SDK where the third part developer using my Framework will be responsibly to add AFNetworking to their project. 构建类似于Aeris SDK的东西,使用我的框架的第三方开发人员负责任地将AFNetworking添加到他们的项目中。

I think that option 3 is the best but i don't know how to do that. 我认为选项3是最好的,但我不知道该怎么做。 How can i dev my framework calling AFNetworking classes/methods but do not include on the final framework product? 我如何设计我的框架调用AFNetworking类/方法,但不包括在最终的框架产品?

Thanks! 谢谢!

That's a very bad practice to use third party library in you library. 在您的库中使用第三方库是一种非常糟糕的做法。
Ideally you should avoid doing that. 理想情况下,你应该避免这样做。

But if you really need it, you can define and add prefixes to class names. 但是如果你真的需要它,你可以定义并为类名添加前缀。
Refer this article Avoiding dependency collisions in iOS static library managed by CocoaPods 请参阅本文避免由CocoaPods管理的iOS静态库中的依赖冲突

Ok. 好。 I decided to go with the option 3. 我决定选择3。

A just added all the header files from any third-party lib to the my framework project (you can also add the .m files but not include them on the static library target). 刚刚将任何第三方库中的所有头文件添加到我的框架项目中(您还可以添加.m文件,但不要将它们包含在静态库目标中)。

And ai also documented everything, so developers using my framework will know what are the dependencies and how to include/install them on their own projects (including third-party lib versions, CocoaPods support, etc). 并且ai还记录了所有内容,因此使用我的框架的开发人员将知道什么是依赖项以及如何在他们自己的项目中包含/安装它们(包括第三方lib版本,CocoaPods支持等)。

I decided not to go with option 1 because that will cause some situations where a project will have two copies of the same lib compiled on the final app. 我决定不使用选项1,因为这会导致某些情况下项目将在最终应用程序上编译同一个lib的两个副本。 Even if a change the namespace for the libs on my framework code (to prevent "duplicated symbols" errors) that will still cause some other possible problems like an APP with larger size, possible bugs related to two or more instances of the same lib running together, etc... 即使更改我的框架代码上的libs的命名空间(以防止“重复的符号”错误)仍然会导致一些其他可能的问题,例如具有更大尺寸的APP,可能的错误与运行相同的lib的两个或更多个实例相关在一起......等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM