Have you ever found yourself wishing you could change the build location of your Xcode project to a more convenient or organized spot on your machine? Unfortunately, Xcode doesn't provide a straightforward setting for this. However, there's a workaround to achieve this, and we're here to guide you through the process.

Before we dive into the steps, let's first understand why you might want to change the build location. Perhaps you've set up a specific directory for your project's derivative data, or maybe you want to organize your projects better across multiple drives. Whatever the reason, this tutorial will help you achieve your goal.

Understanding Xcode's Build Location
By default, Xcode stores build artifacts in the DerivedData folder located in your home Library. This folder contains cached data, build results, and intermediate products. Changing the build location will move these files to a new directory.

It's essential to note that the DerivedData folder is deleted and recreated whenever you clean the build folder or delete the app from the device. Therefore, any changes made to the build location will be permanent unless you perform a clean build or delete the app.
Changing the Build Location for a Single Project

If you want to change the build location for just one project, you can do so by directly manipulating the build settings. Here's how:
- Select your project in the Project Navigator.
- Go to the target you want to modify.
- Click on the "Build Settings" tab.
- Search for "Intermediate Strings File" in the search bar that appears above the list of build settings.
- In the "Intermediate Strings File" line, click on the rightmost arrow in the text field that says "
". - Choose a new location for the build artifacts. Make sure the path you choose is accessible and writable.
- Click "OK" to close the dialog.
- Clean and build your project. Xcode will now create a DerivedData folder at the new location for your selected target.
Changing the Build Location for All Projects

If you want to change the build location for all projects, you can create a custom_ARGS file to override the default DerivedData location.
Here's how to create the custom_ARGS file:
- Open a text editor and create a new file. Save this file as "custom_ARGS" without any extension.
- Add the following line to the file, replacing "~/path/to/your/new/DerivedData" with the desired path: -DerivedDataLocation ~/path/to/your/new/DerivedData
- Save the file with the custom Arguments shell script. Make sure it's executable.
- Launch Xcode, and open the "Execute Script" tool (Place the cursor at the top of the script editor, press `Option+Return`).
- In the "Execute Script" tool, add the following line: set -ex && "${SRCROOT}/custom_ARGS" && echo "DerivedDataLocation is ${DERIVEDDATA Location}"
- Run the script. Xcode will now use the specified location for all DerivedData folders.

Managing the DerivedData Folder
Since the DerivedData folder can grow significantly, especially with large projects, it's a good idea to manage it regularly. You can delete the DerivedData folder to free up space, although this will also delete all cached data and intermediate products, which can slow down the build process.


















To delete the DerivedData folder, you can either:
- Use Finder to navigate to the DerivedData folder and delete it.
- Or use the following Terminal command: rm -rf ~/Library/Developer/Xcode/DerivedData/.
Monitoring DerivedData Size
To keep an eye on the DerivedData folder's size, you can use the following Terminal command, which also deletes files older than a specified number of days:
find ~/Library/Developer/Xcode/DerivedData -name "*.xcuserstate" -exec rm {} \; && find ~/Library/Developer/Xcode/DerivedData -type f -exec stat -x '{}' + | awk '($13 > 0) {print $9; a++} END {print "Number of files: ", a}'
Automating DerivedData Management
To automate the process of managing the DerivedData folder, you can create an Xcode build phase script to delete old files. This way, the DerivedData folder will be cleaned up automatically every time you build your project.
With these tips and tricks, you can now change the build location, manage the DerivedData folder, and maintain a cleaner, more organized Xcode project environment. Happy coding!