Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift framework depending on cocoa pod

Using the newest version of cocoa pods (0.36) I am able to embed cocoa pods written in swift (e.g. Alamofire) into my swift project. Now I introduced a custom framework of my own into the project, which also wants to depend on Alamofire.

What I did in order to accomplish that is to select add the pods framework to my framework as dependency:

Select the Target for my own embedded Swift Framework (Swift Module) and in the "General" tab in the "Linked frameworks and libraries" I added "Pods.framework" as "Required".

However, that is not enough in order to compile as the classes in my own swift framework can not "import Alamofire" as it is not recognised as "available framework".

Adding the Pods.debug.xcconfig and the Pods.release.xcconfig file to the Configurations for the target of my own swift framework, in other words changing the build settings to do all the changes, that cocoa pods do to the build settings of my iOS App target, solves the problem.

It now builds without a problem. It also runs without a problem in the Simulator and my own embedded swift framework successfully uses the frameworks added by cocoa pods.

HOWEVER if I run the same on a device, it compiles and installs without a problem, but then crashes with a fatal error on launch:

dyld: Library not loaded: @rpath/Pods.framework/Pods Referenced from: /private/var/mobile/Containers/Bundle/Application/32D2F1F8-679F-4A5F-8159-28F1C800D0C6/TestingFrameworks.app/Frameworks/mySwiftFramework.framework/mySwiftFramework Reason: image not found 

Apparently not all the settings from the cocoa pods xcconfig file are suited to be added to the build settings of my custom swift framework.

But why does it work in the simulator then? And more important what is the build setting, which I need to correct?

To me it looks like I need to change this build setting:

PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods 

to something else...

like image 430
alex da franca Avatar asked Mar 18 '15 15:03

alex da franca


People also ask

Can a Swift package depend on a Cocoapod?

Unfortunately, swift-atomics doesn't support CocoaPods, so you'll need your own Podspec for it.


1 Answers

I identified the problem. There was simply no pods.framework in the Frameworks/ folder of the embedded framework.

This is due to the fact that the Pods-frameworks.sh don't actually copy things in the right directory.

I managed to fix this problem by:

  1. Removing the useless Embed Pods Frameworks to from the build phases
  2. Adding a Copy Files with destination set to Frameworks

enter image description here

That's it!

like image 141
Pasta Avatar answered Oct 06 '22 16:10

Pasta