制作iOS框架:包括第三方库和代码

时间:2022-01-28 15:39:02

Im making a static iOS framework. I want to use 3rd party code, lets use AFNetworking as an example, in my framework. AFNetworking is popular. I can sense the namespace collisions now. What is the best practice here? As far as I understand I have 3 options:

我正在制作一个静态iOS框架。我想使用第三方代码,让我在框架中使用AFNetworking作为示例。 AFNetworking很受欢迎。我现在可以感知命名空间冲突。这里的最佳做法是什么?据我所知,我有3个选择:

1) Build AFNetworking into my framework, exporting the headers. This lets clients use the version of AFNetworking in my library, but they can't use other frameworks that also link AFNetworking. They rely on me for updates to AFNetworking if they build on it.

1)将AFNetworking构建到我的框架中,导出标头。这允许客户端在我的库中使用AFNetworking版本,但是他们不能使用也链接AFNetworking的其他框架。如果他们以AFNetworking为基础,他们依靠我来更新AFNetworking。

2) Code against the AFNetworking Headers, but make the third parties include AFNetworking in their projects. This adds an extra step for framework consumers, they have to add AFNetworking source. There may be version incompatibilities in the future, but at least if another framework uses AFNetworking they can use that at the same time.

2)针对AFNetworking Headers的代码,但让第三方在其项目中包括AFNetworking。这为框架消费者增加了额外的步骤,他们必须添加AFNetworking源。将来可能存在版本不兼容,但至少如果另一个框架使用AFNetworking,他们可以同时使用它。

3) Re-namespace AFNetworking and keep the headers private. This way I avoid namespace collisions in any way, except that it then becomes really hard to update my copy of AFNetworking. The final binary gets a bit bigger but all interoperability issues are resolved. This is a lot more work for me.

3)重命名AFNetworking并将标头保密。这样我就可以以任何方式避免命名空间冲突,除非它变得非常难以更新我的AFNetworking副本。最终的二进制文件变得更大,但所有互操作性问题都得到了解决。这对我来说还有很多工作要做。

Do I have any other options? What are the best practices?

我还有其他选择吗?什么是最佳做法?

2 个解决方案

#1


6  

A better option is use http://cocoapods.org. This way, is possible to declare the dependencies of the libs and the get a single download for the whole project.

更好的选择是使用http://cocoapods.org。这样,就可以声明libs的依赖关系并获得整个项目的单个下载。

Don't rename headers. Is time-consuming, and hard.

不要重命名标题。耗费时间,而且很难。

P.D: A sample of this:

P.D:这样的一个例子:

http://chariotsolutions.com/blog/post/using-cocoapods-to-manage-private-libraries/

http://chariotsolutions.com/blog/post/using-cocoapods-to-manage-private-libraries/

#2


0  

as far as number 3 goes, it's not a full on "re-namespace" but it's akin to that:

就第3个而言,它不是“重命名空间”的全部,但它类似于:

http://atastypixel.com/blog/avoiding-duplicate-symbol-issues-when-using-common-utilities-within-a-static-library/

http://atastypixel.com/blog/avoiding-duplicate-symbol-issues-when-using-common-utilities-within-a-static-library/

#1


6  

A better option is use http://cocoapods.org. This way, is possible to declare the dependencies of the libs and the get a single download for the whole project.

更好的选择是使用http://cocoapods.org。这样,就可以声明libs的依赖关系并获得整个项目的单个下载。

Don't rename headers. Is time-consuming, and hard.

不要重命名标题。耗费时间,而且很难。

P.D: A sample of this:

P.D:这样的一个例子:

http://chariotsolutions.com/blog/post/using-cocoapods-to-manage-private-libraries/

http://chariotsolutions.com/blog/post/using-cocoapods-to-manage-private-libraries/

#2


0  

as far as number 3 goes, it's not a full on "re-namespace" but it's akin to that:

就第3个而言,它不是“重命名空间”的全部,但它类似于:

http://atastypixel.com/blog/avoiding-duplicate-symbol-issues-when-using-common-utilities-within-a-static-library/

http://atastypixel.com/blog/avoiding-duplicate-symbol-issues-when-using-common-utilities-within-a-static-library/