Search code examples
objective-cxcodeframeworkscocoapodsworkspace

xcode - Sharing code between Framework and Workspace


I have a Framework and a Workspace (project + pods). I want the framework to use classes of workspace (both the project and the pods). Then, when I'll distribute my framework, I need it to have references to the above classes. How do I do that?


Solution

  • Cocoapods provides the means to add a dependancy to a pod. So for example a cocoapod I write could require the project to have the latest AFNetworking cocoapod installed. I can also require other frameworks to be used such as CoreLocation, CoreBluetooth etc.

    If you create your framework as a cocoapod you should be able to add a list of dependencies that will be added when you run:

    pod install

    I've created a framework as a pod before and used something like this in my podspec:

    s.source              =  { :git => ' <destination Git repo> ', :tag => '0.0.1' }
    s.ios.xcconfig        =  { 'FRAMEWORK_SEARCH_PATHS' => '"$(PODS_ROOT)/<MyFrameWorkName>"' }
    s.ios.preserve_paths  =  '<MyFrameWorkName>.framework'
    

    You then should be able to require that cocoapod to have other dependancies, for example:

    s.frameworks   = 'QuartzCore'
    
    s.ios.weak_frameworks =  'CoreBluetooth'
    
    s.dependency 'SDWebImage',                  '~> 3.7'
    s.dependency 'GoogleAnalytics-iOS-SDK',     '3.0.3c'
    

    Now when you / someone else installs your framework through cocoapods, they will have everything they need installed in the project.