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?

Remy Cilia
  • 2,573
  • 1
  • 20
  • 31
  • 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. – Abdullah Apr 07 '15 at 01: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. – Remy Cilia Apr 07 '15 at 02:29

2 Answers2

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!

Remy Cilia
  • 2,573
  • 1
  • 20
  • 31
-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

Community
  • 1
  • 1
Ashok
  • 5,585
  • 5
  • 52
  • 80