Passing Arguments with Xcode 4

The very first post on this blog was a tip on debugging core data on the iPhone that relied on launching the application with an argument. The very next post on Finding memory leaks relied on setting some environment variables. That was well over a year ago and a lot of have changed in the world of iOS including Xcode. The release of Xcode 4 brought a huge number of changes but that inevitably means you have to hunt around a lot at first until you figure out where various settings have ended up.

A big change with Xcode 4 was the introduction of schemes which has taken a number of settings which were spread across Xcode 3 and brought them all into a single place. Schemes also simplify things by dividing the settings into various phases (e.g. build, run, test, profile, archive). The ability to launch an application with a command-line argument or with an environment variable set is now found in the run settings of the scheme.

To access the current scheme use “Product > Edit Scheme…”, select the “Run” phase and then use the “Arguments” tab to set the “Arguments Passed on Launch” and any “Environment Variables you need.

I should add that the way Instruments has improved over the last year neither of these tricks is really necessary any more. The Leaks and Allocations tools in Instruments make it much easier to track down leaking objects and the Clang static analyzer helps prevent leaks in the first place. It took some time for Instruments to support core data running on iOS devices but now that it does there is also not much need to enable the SQLDebug argument.