Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Cocoapods in a Swift 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.

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?

like image 767
Remy Cilia Avatar asked Apr 06 '15 23:04

Remy Cilia


People also ask

Can I use CocoaPods with swift package?

Unfortunately, swift-atomics doesn't support CocoaPods, so you'll need your own Podspec for it. The reason I'm not using them all from SPM is because it's a huge pain to develop them from within SPM.

How do you make a CocoaPods framework in swift?

Implement the podIn the project navigator, right click on the SwiftyLab target and select New File... Choose Swift File as the new file template, click on Next … Name the file as SwiftyLib , make sure this file belongs to the SwiftyLib target and save it in the SwiftyLib folder as shown in the screenshot below.


1 Answers

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!

like image 169
Remy Cilia Avatar answered Oct 20 '22 01:10

Remy Cilia