Xcode - Sharing Code between Framework and Workspace
Cocoapods provides a means to add a dependency to a container. So, for example, a coconut drink I'm writing may require the project to have the latest AFNetworking
cocoapod installed. I can also use other frameworks like CoreLocation
, CoreBluetooth
etc.
If you are building your framework as a cocoapod, you should be able to add a list of dependencies to be added at startup:
pod install
I created the framework as a package 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'
Then you should be able to require cocoapod to have other dependencies like:
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 infrastructure via cocoapods, they will have everything they need to install in the project.
source to share
You can create a new workspace, including all of them, by writing the podfile like this:
workspace 'AllInOne.xcworkspace'
xcodeproj 'Workspace/Workspace.xcodeproj'
xcodeproj 'Framework/Framework.xcodeproj'
target 'ProjectA' do
platform :ios, '8.0'
xcodeproj 'Workspace/Workspace.xcodeproj'
pod 'nameofpod', '~> .1'
end
target 'Framework' do
platform :ios, '8.0'
xcodeproj 'Framework/Framework.xcodeproj'
end
EDIT:
Create a new folder (with a name such as "AllInOne"). In this folder place your framework folder which has framework.xcodeproj and also place your workspace folder. Now create a podfile in the AllInOne folder. At the end, these files should be present in this directory:
AllInOne / Workspace / Workspace.xcodeproj
AllInOne / Framework / Framework.xcodeproj
AllInOne / podfile
AllInOne / AllInOne.xcworkspace
source to share