Can I use CocoaPods when creating a Cocoa Touch Framework?

坚强是说给别人听的谎言 提交于 2019-11-27 17:41:55

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

Try adding the dependency on Alamofire in the framework's podspec as below

Pod::Spec.new do |s|

# Other setup 

# Dependencies
s.dependency "Alamofire"
# Other dependencies if any
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!