如何在Swift框架中使用Cocoapods? [英] How to use Cocoapods in a Swift framework?
问题描述
我正在尝试使用Cocoapods的一些库在Swift中为iOS创建一个新的Cocoa Touch Framework,但我不能让它工作。
我知道有一些关于这个的问题,但它们似乎都无法解决我的问题。
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.
出于测试目的,我刚创建了一个空的Cocoa Touch框架,安装Cocoapods并添加'MBProgressHUD'窗格。
然后,作为 Apple记录('从同一框架目标中导入代码'部分),我在我的伞形标题中导入了MBProgressHUD标题:
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:
#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.
有没有办法在Swift框架中使用CocoaPods?
Is there any way to use CocoaPods in a Swift Framework?
推荐答案
我找到了解决方案,所以我会把它放在这里如果其他人有同样的问题。
I found the solution, so I will let it here in case someone else has the same issue.
因此,Cocoapods支持自0.36版以来的iOS框架,以及在他们的博客中说过,要在框架中使用它,你只需在你的Podfile中添加这一行:
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:
use_frameworks!
之后,在Swift框架中,您不需要在.h文件中包含.h文件伞头,但你需要在任何需要的地方导入模块,例如:
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:
import MBProgressHUD
这对我有用,希望有所帮助!
This is working for me, hope it helps!
这篇关于如何在Swift框架中使用Cocoapods?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!