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

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

问题描述

我使用下面的教程构建了一个框架。

我还获得了这个框架。

我试图在我的内部实现第二个框架,从我在Apple文档中读取的结果框架被称为Umbrella Framework 。

我在框架中添加了第二个框架,使用拖放操作并验证它位于Link Binary With Libraries中。



当我试图在我的框架的一个类中进行下一个导入时:

  #import< CrashReporter / CrashReporter.h> 

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



我也看到了stackoverflow后:
如何在iOS SDK中创建伞架?



更新



任何人试图为iOS提取PLCrashReporter类并将其集成到项目中?

您可以找到我的尝试 here

分发另一个框架的诱惑是可以理解的,但非常沮丧。我会尽力解释为什么(有参数),并且还提供了一些有助于您的案例的很好的选择。



Umbrella框架仅供使用,当你是这两个框架的分销商时,你完全可以控制它们,并且它们将一起分发。

苹果有一个受欢迎的话题,他们说他们不鼓励伞架。


不要创建伞形框架



虽然可以使用Xcode创建伞形框架,但对于大多数开发人员来说,执行
是不必要的,因此不推荐使用。 Apple
使用伞形框架来掩盖操作系统中
库之间的一些相互依赖关系。在几乎所有情况下,您都应该是
能够将您的代码包含在单个标准框架包中。
另外,如果你的代码是足够模块化的,你可以创建
多个框架,但是在这种情况下,
模块之间的依赖将是最小或者不存在的,并且不应该保证
首先,这里是大多数开发人员在这种情况下所做的事情,因为有许多框架,依靠别人。



通知用户您的框架需要使用另一个第三方框架。这在大多数情况下是完全标准的和预期的。然后在系统级别链接到它。就这么简单。你的框架会像使用本地框架一样,发现第三方和功能。以 UIKit 为例。要链接到第三方,请按照下一节中的步骤操作。它完全可以通过标准的方式来完成,但是使用像CocoaPods这样的工具可以让你的项目更容易维护。



要完全回答你的问题 ,而不是通常的方式添加第三方框架,因为您可能遇到问题和复杂性,请使用 CocoaPods 为你添加它。这样,您可以消除可能的问题,并且还可以获得CocoaPods的额外好处,让您获得您需要的第三方的确切版本。



这是CocoaPods Podfile应用程序名为CrashTest

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

为了澄清,在开发框架时,仍然会添加到您的项目中并且可见。这里最大的不同之处在于它将与您的框架分开发布,并且最终用户将不得不将两者都添加到他们的项目中才能使其工作。

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



我上面提到的另一点是版本控制。在发布伞架时,您需要能够控制所涉及的所有框架的版本,并且您无法控制第三方框架。这又会导致类似上面所述的问题。



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

I have build a framework using the following tutorial.

And I also got this 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".

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.

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

Update

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 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.

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

Don't Create Umbrella Frameworks

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.

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.

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.

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.

Here are the reasons why this is done this way.

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天全站免登陆