如何在Swift框架中使用Cocoapods?

时间:2023-01-22 16:23:19

I am trying to create a new Cocoa Touch Framework for iOS in Swift, using some libraries from Cocoapods, but I can't have it work. I know there are some opened questions about that, but none of them seem to fix my problem.

我正在尝试使用Cocoapods中的一些库在Swift中为iOS创建一个新的Cocoa Touch Framework,但我不能让它工作。我知道有一些关于这方面的问题,但它们似乎都无法解决我的问题。

For testing purposes, I just created an empty Cocoa Touch Framework, installed Cocoapods and added the 'MBProgressHUD' pod. Then, as documented by Apple ('Importing Code from Within the Same Framework Target' section), I imported the MBProgressHUD header in my umbrella header like that:

出于测试目的,我刚刚创建了一个空的Cocoa Touch Framework,安装了Cocoapods并添加了“MBProgressHUD”窗格。然后,正如Apple(“从同一框架目标内部导入代码”部分)所记录的那样,我在我的伞形标题中导入了MBProgressHUD标头,如下所示:

#import "MBProgressHUD.h"

But when I compile, I have this error:

但是当我编译时,我有这个错误:

include of non-modular header inside framework module

I did set the 'Allow Non-modular includes in Framework Modules' setting to Yes, but it doesn't have any effect.

我确实将“允许非模块化包含在框架模块中”设置为“是”,但它没有任何效果。

Is there any way to use CocoaPods in a Swift Framework?

有没有办法在Swift框架中使用CocoaPods?

2 个解决方案

#1


15  

I found the solution, so I will let it here in case someone else has the same issue.

我找到了解决方案,所以我会在这里让它以防其他人有同样的问题。

So, Cocoapods supports iOS frameworks since version 0.36, and as it's said in their blog, to use it in a framework, you just have to add this line in your Podfile:

因此,Cocoapods支持自0.36版本以来的iOS框架,正如在他们的博客中所说,要在框架中使用它,你只需要在你的Podfile中添加这一行:

use_frameworks!

After that, in a Swift framework, you don't need to include the .h files in your umbrella header, but you do need to import the module wherever you need it, for instance:

之后,在Swift框架中,您不需要将.h文件包含在伞形标题中,但您需要在任何需要的地方导入模块,例如:

import MBProgressHUD

This is working for me, hope it helps!

这对我有用,希望对你有所帮助!

#2


-1  

Using 'Objective-C bridging header' we can make use of Objective-C frameworks in Swift.

使用'Objective-C桥接头',我们可以在Swift中使用Objective-C框架。

Refer the following, It will explain how to make use of Objective-C framework(For example Parse framework) in Swift.

请参阅以下内容,它将解释如何在Swift中使用Objective-C框架(例如Parse框架)。

Link1
Link2

•Link1•Link2

#1


15  

I found the solution, so I will let it here in case someone else has the same issue.

我找到了解决方案,所以我会在这里让它以防其他人有同样的问题。

So, Cocoapods supports iOS frameworks since version 0.36, and as it's said in their blog, to use it in a framework, you just have to add this line in your Podfile:

因此,Cocoapods支持自0.36版本以来的iOS框架,正如在他们的博客中所说,要在框架中使用它,你只需要在你的Podfile中添加这一行:

use_frameworks!

After that, in a Swift framework, you don't need to include the .h files in your umbrella header, but you do need to import the module wherever you need it, for instance:

之后,在Swift框架中,您不需要将.h文件包含在伞形标题中,但您需要在任何需要的地方导入模块,例如:

import MBProgressHUD

This is working for me, hope it helps!

这对我有用,希望对你有所帮助!

#2


-1  

Using 'Objective-C bridging header' we can make use of Objective-C frameworks in Swift.

使用'Objective-C桥接头',我们可以在Swift中使用Objective-C框架。

Refer the following, It will explain how to make use of Objective-C framework(For example Parse framework) in Swift.

请参阅以下内容,它将解释如何在Swift中使用Objective-C框架(例如Parse框架)。

Link1
Link2

•Link1•Link2