10

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
  • I had similar problem. I ended up with copying cocoapods source code to my framework and making Objective-C headers public. I read at couple of places it could be done by help of modules but I was not not able to do so. If you are able to do with Objective-C modules do let me know. Commented Apr 7, 2015 at 1:17
  • I actually also tried to do that, but I need the AWS SDK, which uses some external frameworks, and I wasn't able to find the source codes for them. Commented Apr 7, 2015 at 2:29

2 Answers 2

15

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!

Sign up to request clarification or add additional context in comments.

2 Comments

I also needed to set "allow non-modular includes in framework modules" to yes in the build settings.
This does not appear to work if you need to support iOS7 and therefore cannot employ use_frameworks!
-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.