如何在另一个框架内添加一个框架(Umbrella Framework) [英] How to add a framework inside another framework (Umbrella Framework)

查看:27
本文介绍了如何在另一个框架内添加一个框架(Umbrella Framework)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用以下教程构建了一个框架.

I have build a framework using the following tutorial.

我也得到了这个框架.

我正在尝试在我的内部实现第二个框架,根据我在 Apple 文档中阅读的内容,生成的框架称为Umbrella Framework".

I am trying to implement the second Framework inside mine, from what I read in the Apple docs the resulting framework is called "Umbrella Framework".

我使用拖放在框架中添加了第二个框架,并验证它是否在Link Binary With Libraries"中.

I added the second framework in framework using drag and drop and the verify that it is in the "Link Binary With Libraries".

在我尝试在我的框架的一个类中进行下一次导入之后:

And after I tried to make the next import in one of the classes of the my framework:

#import <CrashReporter/CrashReporter.h>

我收到一个错误,因为导入的框架不可见.

I received an error as the imported framework is not visible.

我也看过 stackoverflow 帖子:如何在 iOS SDK 中创建伞形框架?

Also I have seen the stackoverflow post: How to create an umbrella framework in iOS SDK?

有没有人尝试为 iOS 提取 PLCrashReporter 类并将其集成到项目中?

Have anyone tried to extract the PLCrashReporter classes for iOS and integrate the in a project?

您可以在此处找到我的尝试.

You can find my attempt here.

推荐答案

分发另一个框架的诱惑是可以理解的,但强烈反对.我将尝试解释为什么会这样(带参数),并提供一些对您的情况有帮助的很好的替代方案.

The temptation to distribute another framework is understandable, but highly discouraged. I'll try to explain why that is (with arguments), and also provide some great alternatives that will help in your case.

Umbrella 框架是供使用的,只有当你是两个框架的分发者时,你才能完全控制它们,它们才会一起分发.

Umbrella framework are intended for use, only when you are the distributor of both frameworks, you have full control over them, and they will be distributed together.

Apple 有一句关于该主题的流行语录,他们说他们不鼓励使用伞式框架.

There is a popular quote on the topic from Apple, where they say that they discourage umbrella frameworks.

不要创建伞式框架

虽然可以使用 Xcode 创建伞式框架,但所以对于大多数开发人员来说是不必要的,不推荐使用.苹果使用伞式框架来掩盖一些相互依赖关系操作系统中的库.在几乎所有情况下,您都应该能够将您的代码包含在单个标准框架包中.或者,如果您的代码足够模块化,您可以创建多个框架,但在这种情况下,模块将是最小的或不存在的,不应保证为他们制作一把雨伞.

While it is possible to create umbrella frameworks using Xcode, doing so is unnecessary for most developers and is not recommended. Apple uses umbrella frameworks to mask some of the interdependencies between libraries in the operating system. In nearly all cases, you should be able to include your code in a single, standard framework bundle. Alternatively, if your code was sufficiently modular, you could create multiple frameworks, but in that case, the dependencies between modules would be minimal or nonexistent and should not warrant the creation of an umbrella for them.

首先,这是大多数开发人员在这种情况下所做的事情,因为有许多框架依赖于其他框架.

First, here is what most developers do in this situation, since there are many frameworks out there that rely on others.

通知用户您的框架需要使用另一个第三方框架.在大多数情况下,这是完全标准的和预期的.然后在系统级别链接到它.就这么简单.您的框架将找到第三方并无缝运行,就像使用原生框架一样.以 UIKit 为例.要链接到第三方,请按照下一节中的步骤操作.它当然可以通过标准方式完成,但使用 CocoaPods 之类的工具将使您的项目更易于维护.

Inform the user that your framework requires the use of another third party framework. This is completely standard and expected in most cases. Then link to it at the system level. It's as simple as that. Your framework will find the third party and function seemlesly, just like using a native framework. Take UIKit for example. To link to the third party, follow the steps in the next section. It can certainly be done the standard way, but using a tool like CocoaPods will make your project easier to maintain.

要完整回答您的问题,不要以通常的方式添加第三方框架,因为您可能会遇到问题和并发症,请使用 CocoaPods 为您添加.这样,您就可以消除可能的问题,并获得 CocoaPods 的额外好处,让您获得所需的第三方的确切版本.

To completely answer your question, instead of adding the third party framework the usual way, since you could run into problems and complications, use CocoaPods to add it for you. This way, you eliminate possible issues and also get the added benefit of CocoaPods getting you the exact version of the third party you will need.

这是一个名为CrashTest"的应用程序的 CocoaPods Podfile

Here is the CocoaPods Podfile for an app called "CrashTest"

target 'CrashTest' do
pod 'PLCrashReporter', '~> 1.2.0'
end

澄清一下,当您开发框架时,它仍然会添加到您的项目中并且可见.这里最大的区别在于它将与您的框架分开分发,最终用户必须将两者都添加到他们的项目中才能使事情正常进行.

Just to clarify, when you are developing the framework, it will still be added to your project and visible. The big difference here is that it will be distributed separately from your framework, and end users will have to add both to their projects in order to make things work.

以下是这样做的原因.

例如,您希望在框架中包含 PLCrashReporter.假设另一个框架供应商也希望将其包含在他们的框架中.使用这两个框架的应用程序将包含两次 PLCrashReporter(作为每个伞式框架的一部分).甚至可能有不同的版本.这可能会导致用户应用程序内部出现严重问题.如果两个伞式框架都链接到 PLCrashReporter,如上一节所述,则可以完全避免此问题.

For example, you would like to include PLCrashReporter in your framework. Say another framework vendor wants to include it in theirs as well. The application using both frameworks will have PLCrashReporter included twice (as part of each umbrella framework). Possible even different versions of it. This could lead to serious issues inside of the user application. If both umbrella frameworks are linking to PLCrashReporter, as described in the previous section, this issue would be avoided completely.

我在上面谈到的另一点是版本控制.在分发伞形框架时,需要能够控制所有涉及的框架的版本,并且无法控制第三方框架.这将再次导致与上述问题类似的问题.

Another point, which I touched on above is versioning. When distributing an umbrella framework, you need to be able to control the versions of all frameworks involved, and you have no control over the third party framework. Which would again lead to a similar problem as the one described above.

我知道这种方法不能直接回答问题,但它试图阻止不良做法,同时指出行业标准的做事方式.

I know that this approach does not provide a direct answer to the question, but it's trying to discourage a bad practice instead, while pointing the industry standard way of doing things.

这篇关于如何在另一个框架内添加一个框架(Umbrella Framework)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆