How to use Cocoapods in a Swift framework?

2019-02-05 06:21发布

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.

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.

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

2条回答
Anthone
2楼-- · 2019-02-05 06:52

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:

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:

import MBProgressHUD

This is working for me, hope it helps!

查看更多
你好瞎i
3楼-- · 2019-02-05 06:56

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

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

Link1
Link2

查看更多
登录 后发表回答