Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use CocoaPods when creating a Cocoa Touch Framework?

I'm creating a new Cocoa Touch Framework (MyFramework.framework), which will have a dependency on Alamofire. This framework will be written in Swift. As a test I started a new Cocoa Touch Framework project:

File > New > Project > Framework & Library > Cocoa Touch Framework 

Then, in the terminal I performed:

pod init 

under this projects directory. In the newly created Podfile I added the following:

source 'https://github.com/CocoaPods/Specs.git' # Uncomment this line to define a global platform for your project platform :ios, '8.0' # Uncomment this line if you're using Swift use_frameworks!  pod 'Alamofire', '~> 3.0' 

Once again, in the Terminal I performed:

pod install 

and started coding away.

Everything seemed well and good till I used the MyFramework.framework Product in a Single View Project. When I attempt to run the project I get the following issue:

dyld: Library not loaded: @rpath/Alamofire.framework/Alamofire Referenced from: /Users/me/Library/Developer/CoreSimulator/Devices/87DA70B6-49BF-441E-BD81-F4A80B0792CF/data/Containers/Bundle/Application/2E414EA8-7E54-4D71-9295-566D4FAAADE2/test.app/Frameworks/MyFramework.framework/MyFramework Reason: image not found 

I thought that Cocoa Touch Framework projects were inherently Dynamic, and therefore would include all dependencies.

Can anyone tell me why this is happening and how I may be able to fix it? Is this an issue with CocoaPods or am I missing something?

I'm a noob to Stack Overflow so please let me know if you need more information from me.

Thanks!

like image 762
bneu Avatar asked Mar 10 '16 20:03

bneu


People also ask

Can you use SPM and CocoaPods?

Cocoapods + SPM 🚀 Now your library supports both cocoa pods and SPM.

What are CocoaPods used for?

What is it and what does it do? Cocoapods is an application level dependency manager that runs on objective-c, swift, and any other programming languages that run on Objective-C. It focuses on source-based distribution of third party code and allows automatic integration to your Xcode projects.


1 Answers

Unfortunately CocoaPods doesn't support use with Cocoa Touch Framework target. I found a few references to this while digging through their issues on GitHub:

We don't really support integrating Pods into framework targets...
-neonichu on Nov 4, 2015

and

...in order for this to "just work", CP would need to do a recursive analysis of dependencies in your Xcode project and also somehow ensure that you would never use the build product in another context.
-neonichu on Jul 7, 2015


So far I've found two ways to deal with the issue:

The right way is to create a new pod spec for your framework and bring it in to your main project via CocoaPods. This resolves all of the problems CococaPods has with the dependency graph and is the recommended solution from the CocoaPods developers.

The easy way is to include the pods from your framework in your main project. This seems to work, but frankly I don't know why. This is the Podfile from my test project:

platform :ios, '9.0' use_frameworks!  def myfirstframework_pods     pod 'Alamofire', '~> 3.0' end  target 'MyApp' do     pod 'SwiftKeychainWrapper', '~>1.0'     myfirstframework_pods end  target 'MyFirstFramework' do     myfirstframework_pods end 
like image 127
Dallas Edwards Avatar answered Sep 28 '22 06:09

Dallas Edwards