如何在 Swift 框架中使用 Cocoapods?

How to use Cocoapods in a Swift framework?(如何在 Swift 框架中使用 Cocoapods?)
本文介绍了如何在 Swift 框架中使用 Cocoapods?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)