Make Custom Debug Build Configurations Play Nicely With CocoaPods


To test the Word Counter during development, I have long used a special build target. But that doesn’t scale well if all I want is change a preprocessor macro to switch from file-based to in memory storage, forexample.

I’ve never played around with build configurations in Xcode. They work well with Schemes, though, and setting up a build configuration and a scheme is much less overhead than maintaining a customtarget.

Hit the + button and then duplicate the existing Debug configuration.

From the project view, it’s easy to duplicate the existing debug buildconfiguration.

I’ve done this twice for the Word Counter: once for an in memory store, once using test data. In the second case, the clock always points to the same time and the app uses different files. This way I don’t destroy my personal records and have nice presets to makescreenshots.

To be able to build and run the project using the new configuration, add ascheme.

Duplicate the existing scheme using the cog icon

From the scheme editor, duplicate the existing scheme for running the app and change its name. I added a “In Memory” suffix to have it read nicely in the list ofschemes.

Change the used build configuration from the “Run” setting to the new configuration. You may also want to change the used configuration for testing, but I didn’t, since the tests stay thesame.

Set the configuration to the one you’ve just created.

Now we have to tameCocoaPods.


You will probably get a warning with pod install :

[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set.…

In my case, there were a dozen ofthese.

They continued likethis:

In order for CocoaPods integration to work at all, please either set the base configurations of the target InteractionTests to Pods/Target Support Files/Pods/Pods.debug in memory.xcconfig or include the Pods/Target Support Files/Pods/Pods.debug in memory.xcconfig in your buildconfiguration.

You see that the InteractionTests target under the “Debug In Memory” configuration is expected to use a different .xcconfig . Although CocoaPods created some new of these, I wasn’t able to pick them inXcode.

To solve the problem, I performed thesesteps:

Tell CocoaPods that the new configurations are descendants from the “Debug” configuration. I added xcodeproj 'WordCounter', 'Debug In Memory' => :debug, 'Debug Test Data' => :debug to my Podfile at rootlevel. Then I reset all newly created configurations. Instead of the Pods.debug configuration of some targets, I set all target configurations to“None”. Run pod install to make CocoaPods attach its .xcconfig files in the appropriate slots – those I’ve justcleared.

Now I get different warnings: the test targets of the new configurations use the wrong .xcconfig files. Instead of Pods-InteractionTests.debug.xcconfig , it is set to Pods.debug.xcconfig .

Turns out this is because my 18-months-old podfile had global podsdefined.

Modern CocoaPodsfile
First, reset all new configs to ‘None’; then I found something doesn’t seem to work. The third image shows what it’s supposed to look like in the end.


platform :osx, '10.9'use_frameworks!xcodeproj 'WordCounter', 'Debug In Memory' => :debug, 'Debug Test Data' => :debuglink_with ['WordCounter', 'CedarSpecs', 'InteractionTests']pod 'CocoaLumberjack'pod 'LaunchAtLoginController', :git => ""pod 'CorePlot', :git => ''target "CedarSpecs", :exclusive => true do pod 'Cedar'endtarget "InteractionTests", :exclusive => true do pod 'OCHamcrest', '~> 4.2' pod 'OCMockito', '~> 2.0' #OCHamcrest 4 supportend

I nowuse:

platform :osx, '10.9'use_frameworks!xcodeproj 'WordCounter', 'Debug In Memory' => :debug, 'Debug Test Data' => :debugdef shared_pods pod 'CocoaLumberjack' pod 'LaunchAtLoginController', :git => "" pod 'CorePlot', :git => ''endtarget "WordCounter" do shared_podsendtarget "CedarSpecs" do shared_pods pod 'Cedar'endtarget "InteractionTests" do shared_pods pod 'OCHamcrest', '~> 4.2' pod 'OCMockito', '~> 2.0' #OCHamcrest 4 supportend

Seems to solves the exclusivity problem from before just fine. (Whatever that was. I don’t rememberanymore.)

No warnings left for me now and everything buildsfine.

If that doesn’t seem to work, delete the Pods folder from your project: mine contained stale and missing files. After deleting it, pod install added fresh files justfine.