我正在尝试使用 Cocoapods 中的一些库在 Swift 中为 iOS 创建一个新的 Cocoa Touch 框架,但我无法让它工作.我知道有一些未解决的问题,但似乎没有一个能解决我的问题.
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"pod.然后,正如 Apple 记录的('Importing来自同一框架目标部分的代码),我在我的伞头文件中导入了 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 文件,但您需要在任何需要的地方导入模块,例如:
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!