Can I use CocoaPods when creating a Cocoa Touch Framework?

后端 未结 2 1408
天涯浪人
天涯浪人 2020-12-04 12:00

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

相关标签:
2条回答
  • 2020-12-04 12:44

    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
    
    0 讨论(0)
  • 2020-12-04 12:55

    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
    
    0 讨论(0)
提交回复
热议问题