How do I specify multiple targets in my podfile for my Xcode project?

Since CocoaPods 1.0 has changed the syntax, instead of using link_with, do something like:

# Note; name needs to be all lower-case.
def shared_pods
    pod 'SSKeychain', '~> 0.1.4'
    pod 'INAppStoreWindow', :head
    pod 'AFNetworking', '1.1.0'
    pod 'Reachability', '~> 3.1.0'
    pod 'KSADNTwitterFormatter', '~> 0.1.0'
    pod 'MASShortcut', '~> 1.1'
    pod 'MagicalRecord', '2.1'
    pod 'MASPreferences', '~> 1.0'
end

target 'Sail' do
    shared_pods
end

target 'Sail-iOS' do
    shared_pods
end

Old answer Pre CocoaPods 1.0:

Yes there is a better way! Check out link_with where you can do link_with 'MyApp', 'MyOtherApp' to specify multiple targets.

I use this with unit tests like link_with 'App', 'App-Tests' (beware of spaces in target’s names).

Example:

platform :osx, '10.8'

link_with 'Sail', 'Sail-Tests'

pod 'SSKeychain', '~> 0.1.4'
pod 'INAppStoreWindow', :head
pod 'AFNetworking', '1.1.0'
pod 'Reachability', '~> 3.1.0'
pod 'KSADNTwitterFormatter', '~> 0.1.0'
pod 'MASShortcut', '~> 1.1'
pod 'MagicalRecord', '2.1'
pod 'MASPreferences', '~> 1.0'

Approach using abstract_target:

In below example, the 'ShowsiOS', 'ShowsTV' and 'ShowsTests' targets have their own separate pods, plus ShowsKit inherited, because they are all child of the dummy target 'Shows'.

# Note: There are no targets called "Shows" in any of this workspace's Xcode projects.
abstract_target 'Shows' do
  pod 'ShowsKit'

  target 'ShowsiOS' do
    pod 'ShowWebAuth'
  end

  target 'ShowsTV' do
    pod 'ShowTVAuth'
  end

  # Our tests target has its own copy
  # of our testing frameworks
  # (beside inheriting ShowsKit pod).

  target 'ShowsTests' do
    inherit! :search_paths
    pod 'Specta'
    pod 'Expecta'
  end
end

Leave a Comment