Xcode 4 DerivedData and cleaning the build directory

The added capabilities in Xcode 4 can at first be a bit overwhelming to anybody migrating from Xcode 3. For me this most often leads to frustration at not being able to quickly do something in Xcode 4 that I could previously do easily in Xcode 3. However with time this frustration goes away as I develop a greater understanding of why Xcode 4 works a certain way (or I find a workaround).

To give a simple example, when building an iOS app for distribution with Xcode 3 I always liked to completely delete the build directory from the project to be sure that I got a clean build. Of course you could always clean a target (or all targets) from the Xcode menu but there is something reassuring about knowing that you are absolutely building everything from scratch.

Deleting the build directory in an Xcode 3 project was easy as the build directory was located inside the project directory so there was never any confusion about what to delete. With Xcode 4 if you take a look inside the project directory the build directory has disappeared.

Derived Data

With Xcode 4 came the concept of a workspace that allows multiple projects to be grouped together. Each workspace gets a unique set of symbol indexes, build products, window layouts, etc., otherwise referred to by Xcode as derived data. Since a single project can belong to more than one workspace this derived data is no longer contained under the individual project directory.

By default Xcode stores this data for all projects in a single shared folder under your home directory at the following location:

~/Library/Developer/Xcode/DerivedData

You can change this location from the Xcode preferences if you wish. If for some reason you want to go back to storing this data under the individual project directories you should change the Derived Data path to “Relative” and specify the directory name:

If you do go back to a project specific directory you may want to add the directory name to your .gitignore (or equivalent) file so that you do not check the files into your source code repository.

The actual directory name used for each projects derived data is named from the workspace name and a hash of the directory path so you end up with directory names such as AirPrinter-bcewjhqefskmeegzucuwvqazdjlo for a workspace named AirPrinter. Inside this directory are subdirectories for Build, Index and Logs containing all of the derived data:

Cleaning

In Xcode 4 the Product > Clean menu option cleans up the build directory for all targets by deleting the app and dSYM files along with the precompiled headers. If this is not enough for your peace of mind you could navigate down to the correct DerivedData directory for your current workspace and manually delete the build directory. Luckily the Xcode team has taken pity on the paranoid and added a menu option to completely delete the build directory. To access the option open the Product menu and use the Option key to show the Clean Build Folder option.

After it is done the Build sub-directory no longer exists under the DerivedData directory so you can clean build with confidence…

Never miss a post!

iOS Size Classes Cheat Sheet

Subscribe and get my free iOS Size Classes Cheat Sheet

Success! Now check your email to confirm your subscription and download your free guide to iOS Size Classes.

There was an error submitting your subscription. Please try again.

Unsubscribe at any time.
No time to watch WWDC videos?

Sign up to get my iOS posts direct to your inbox and I will send you a free PDF of my iOS Size Classes Cheat Sheet.

OK! Check your inbox (or spam folder) for an email to confirm your details and download your free guide to iOS Size Classes.

There was an error submitting your subscription. Please try again.

Unsubscribe at any time.
Archives Categories