5

I'm trying to wrap my head around this complex setting:

I have two projects and a shared library. The shared library is a cocoapod.

I would like to be able to use a single workspace to develop in. There are some duplicated pod definitions, but I have this working in a single Podfile.

Here's where it gets complicated:

I want each project/library in its own git repo. Each repo must be able to live on its own; have its own Podfile, be tested/deployed via CI, etc.

Another wrench: we are the git-flow branching strategy... The master branch of project A/B must pull the master branch of the library. The develop branch of project A/B must pull the develop branch of the library.

Has anyone figured this out? Am I going about this in an ass-backwards way?

Here is a working root workspace Podfile:

platform :ios, "7.0"
inhibit_all_warnings!

workspace 'Root.xcworkspace'
xcodeproj 'SharedLibrary/SharedLibrary.xcodeproj'
xcodeproj 'ProjectA/ProjectA.xcodeproj'
xcodeproj 'ProjectB/ProjectB.xcodeproj'

target 'SharedLibrary' do
    xcodeproj 'SharedLibrary/SharedLibrary.xcodeproj'
    pod 'AFNetworking', '~> 2.0'
    pod 'CocoaLumberjack'
end

target 'ProjectA' do
    xcodeproj 'ProjectA/ProjectA.xcodeproj'
    pod 'AFNetworking', '~> 2.0'
    pod 'CocoaLumberjack'
    pod 'MagicalRecord', '~> 2.2'
    pod 'SharedLibrary', :path => './SharedLibrary/'
end

target 'ProjectB' do
    xcodeproj 'ProjectB/ProjectB.xcodeproj'
    pod 'AFNetworking', '~> 2.0'
    pod 'CocoaLumberjack'
    pod 'MagicalRecord', '~> 2.2'
    pod 'SharedLibrary', :path => './SharedLibrary/'
end

Here is the shared library's podspec:

Pod::Spec.new do |s|

  s.name         = "SharedLibrary"
  s.version      = "0.0.1"

  s.platform     = :ios, "7.0"
  s.source       = { :git => "http://not.really.uploaded.anywhere.yet/SharedLibrary.git", :tag => "0.0.1" }
  s.source_files  = "SharedLibrary", "SharedLibrary/**/*.{h,m}"
  s.public_header_files = "SharedLibrary/**/*.h"

  s.dependency 'AFNetworking', '~> 2.0'
  s.dependency 'CocoaLumberjack'

end
Matthew Crenshaw
  • 322
  • 1
  • 4
  • 14

1 Answers1

0

What I did was to define an "exclusive" target for the CocoaPod library. An exclusive target will not link with the rest of the Podfile pods. Basically what you're going to have to do is define your target that points to the Xcode project. Then you need to add the CocoaPod as a dependency using the podspec. Because it's an exclusive target, it won't link with itself. For example,

source 'https://github.com/CocoaPods/Specs.git'

target 'SharedLibrary', :exclusive => true do
  xcodeproj 'SharedLibrary/SharedLibrary.xcodeproj'
end

pod 'SharedLibrary', :path => 'SharedLibrary/'

does what you would need it to. The only caveat is that every time you add a public header to the library, you need to run pod update to use it in your project.

Podfile Syntax on Targets

Jadar
  • 1,643
  • 1
  • 13
  • 25