Cocoapods for an existing multi-project workspace

TL;DR — Working pod file is at the bottom of the post

I wanted to add SurveyMonkey SDK to our iOS app. Going through their developer page I noticed they have a pod for it, I figured it’s a good time to add cocoapods to Hello Heart iOS app workspace.

Our app workspace has 5 projects.

  1. A specific version of RestKit (ugh, so much legacy)
  2. Commons project, mainly holds utils and types every part of the app needs.
  3. Models project, every model that is used in the app, such as our persistent data type etc.
  4. Controllers project (You see where we’re going with this)
  5. UI project

Every project exist within their own library, which in turn is under the same path level as the app workspace. Our workspace directory

The project file is inside each of these directories.

Cocoapods has a great website and howtos, so I won’t cover the basics. I wanted a single Podfile, in the same directory of the workspace that will control each one of the projects, and also control each target within that project with separate pods for each project and sometimes for each target.

Controlling different pods was solved using this awesome post by natashatherobot.com. But I just couldn’t settle between cocoapods help and all the StackOverflow questions and answers on how exactly should I build the pod file for the directory tree I described.

First Podfile was for a single project under the workspace:

# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!

workspace 'ios-client'

xcodeproj 'Hello Doctor/Hello Heart.xcodeproj'

def ui_pods
pod 'Reachability'
pod 'surveymonkey-ios-sdk', '~> 1.0'
end

target 'Hello Heart' do
ui_pods
end

target 'Hello Heart • Premium' do
ui_pods
end

Very simple, declaring the xcode project file location under the workspace, specifying the pods, and adding them to each relevant target.

Let’s add the second project

# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!

workspace 'ios-client'

xcodeproj 'HDControllers/HDControllers.xcodeproj'
xcodeproj 'Hello Doctor/Hello Heart.xcodeproj'

def controller_pods
pod 'Reachability'
end

def ui_pods
pod 'Reachability'
pod 'surveymonkey-ios-sdk', '~> 1.0'
end

target 'HDControllers' do
controller_pods
end

target 'HDControllersHP' do
controller_pods
end

target 'Hello Heart' do
ui_pods
end

target 'Hello Heart • Premium' do
ui_pods
end

Looks simple right? NO! 
Executing pod install will generate “unable to find a target named HDControlles”

Finally after a lot of trial and error I found the solution, each target should declare which project she relates to

# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!
workspace 'ios-client'
xcodeproj 'HDControllers/HDControllers.xcodeproj'
xcodeproj 'Hello Doctor/Hello Heart.xcodeproj'
def controller_pods
pod 'Reachability'
end
def ui_pods
pod 'Reachability'
pod 'surveymonkey-ios-sdk', '~> 1.0'
end
target 'HDControllers' do
xcodeproj 'HDControllers/HDControllers.xcodeproj'
controller_pods
end
target 'HDControllersHP' do
xcodeproj 'HDControllers/HDControllers.xcodeproj'
controller_pods
end
target 'Hello Heart' do
xcodeproj 'Hello Doctor/Hello Heart.xcodeproj'
ui_pods
end
target 'Hello Heart • Premium' do
xcodeproj 'Hello Doctor/Hello Heart.xcodeproj'
ui_pods
end
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.