If Xcode is showing stale changes, reporting strange compiler errors, or producing a build that no longer matches your code, clearing its build cache can often help. The quickest option is usually Product > Clean Build Folder. If that does not fix the problem, you can remove the project’s Derived Data so Xcode rebuilds its intermediate files from scratch.
This guide explains how to clear the Xcode build cache safely, what each cleanup method removes, and when to use it. It also covers Swift Package Manager caches, common troubleshooting steps, and ways to avoid deleting files you still need.
What Is the Xcode Build Cache?
Xcode stores generated files so it can build your app faster the next time you work on it. These files can include compiled code, indexes used for code completion, module data, build logs, and other intermediate products. Much of this information is stored in a folder called Derived Data.
Build caches are useful because Xcode does not need to rebuild every part of your project after every small change. However, cached files can occasionally become outdated or inconsistent. This may happen after changing Xcode versions, switching branches, updating dependencies, changing build settings, or interrupting a build.
Clearing the cache removes generated data, not your source code. Xcode recreates the required files when you build again. The first build after cleanup may take longer because the app and its dependencies need to be compiled again.
Method 1: Clean the Build Folder in Xcode
Start with Xcode’s built-in clean command. It is the least disruptive way to remove the current project’s built products and try a fresh build.
- Open your project or workspace in Xcode.
- In the macOS menu bar, select Product.
- Hold down the Option key to reveal the additional clean command.
- Select Clean Build Folder.
- Build the project again with Product > Build, or press
Command-B.
In many Xcode versions, Clean Build Folder is also available directly under the Product menu with the shortcut Shift-Command-K. If you only see Clean, use that option or hold Option while opening the menu to find the more thorough command.
This is a good first step when you have recently changed code or build settings and suspect that Xcode is using an old build product. It is quick and does not require you to locate folders manually. If the issue continues, clear Derived Data next.
Method 2: Delete Derived Data from Xcode Settings
Deleting Derived Data is the most common way to clear the Xcode build cache for a project. You can remove it through Xcode’s settings without typing a Terminal command.
- Open Xcode.
- Choose Xcode > Settings on newer versions, or Xcode > Preferences on older versions.
- Select the Locations tab.
- Find the Derived Data location.
- Click the small arrow next to the folder path to open it in Finder.
- Quit Xcode, then move the relevant project folder inside Derived Data to the Trash.
- Reopen Xcode and build your project again.
Derived Data is often stored at ~/Library/Developer/Xcode/DerivedData, though the location may differ if you changed it in Xcode settings. Each project normally has its own folder with a generated name. Removing only the folder associated with the project you are troubleshooting avoids clearing cached data for every other project.
You can also delete the entire Derived Data folder if you want to clear caches for all projects. Xcode will recreate the folders it needs, but indexing and the next builds for multiple projects may take longer. Make sure you are deleting Derived Data, not a folder containing your project’s original source files.
Method 3: Clear Derived Data Using Terminal
If you prefer Terminal, you can remove Derived Data directly. First, quit Xcode so it is not actively using the files. Then run this command to open the folder in Finder:
open ~/Library/Developer/Xcode/DerivedData
In Finder, identify the folder for the project you want to reset and move it to the Trash. This visual method is safer than guessing the project’s generated folder name.
To remove all Derived Data from Terminal, use:
rm -rf ~/Library/Developer/Xcode/DerivedData
Use this command carefully. The rm -rf command permanently removes the specified files without asking for confirmation. Check the path before pressing Return, and do not replace it with a broad path such as your home folder or the whole Library folder. If you are unsure, use Finder or Xcode’s Locations settings instead.
After clearing Derived Data, reopen the project and build again. The first build can take noticeably longer while Xcode recreates indexes, compiled modules, and other generated files.
Method 4: Clean a Project with xcodebuild
You can also ask Xcode’s command-line build tool to clean a project. From Terminal, navigate to the directory containing your project or workspace and run the appropriate command.
For a project file, use a command like:
xcodebuild -project MyApp.xcodeproj -scheme MyApp clean
For a workspace, use:
xcodebuild -workspace MyApp.xcworkspace -scheme MyApp clean
Replace MyApp with the actual project, workspace, and scheme names. A clean command removes build products for the selected scheme and configuration, but it is not always the same as deleting all of that project’s Derived Data. If you need a complete cache reset, remove the project’s Derived Data folder as described above.
If you are not sure which scheme to use, open the project in Xcode and check the scheme selector beside the Run button. You can also list schemes from the command line with xcodebuild -list, adding the appropriate project or workspace option when needed.
How to Clear Swift Package Manager Caches
If your project uses Swift packages, cleaning the build folder may not clear every package-related cache. A dependency may still be present in a package cache even after you clean the project’s compiled products.
To refresh package information from Xcode, choose File > Packages > Reset Package Caches. Afterward, choose File > Packages > Resolve Package Versions if you need Xcode to fetch or resolve the dependencies again. Menu names can vary slightly between Xcode versions.
Reset package caches only when you suspect a package has become corrupted, a dependency update is not being recognized, or package resolution is failing unexpectedly. Resetting them may require an internet connection and can make the next dependency-resolution step slower. Avoid deleting package folders manually unless you know which cache you are targeting.
When Should You Clear the Xcode Build Cache?
Clearing a cache is useful when there is a specific build problem, but it should not be the first response to every warning or error. Consider cleaning the build folder or Derived Data when:
- Xcode appears to build an older version of your code after you have made changes.
- You see unusual compiler or module errors that persist after correcting the source code.
- A project fails immediately after an Xcode or Swift version update.
- You have switched branches and the new branch uses different build settings or dependencies.
- Code completion, indexing, or generated build products seem stuck or inconsistent.
- A dependency update is not reflected in the build even after resolving packages.
Cache cleanup cannot fix every build failure. A missing file, incorrect signing setting, unsupported deployment target, broken dependency, or genuine source-code error will remain after the cache is removed. Read the full error message and check recent project changes before repeating cleanup steps.
What You Should Not Delete
Do not delete your project’s source folder when you are trying to clear the Xcode build cache. Derived Data is generated output; your repository contains the files you wrote and the project configuration you need. If you use Git, verify that important changes are committed or backed up before performing any broad cleanup.
Also avoid erasing a simulator or deleting all simulator data as a routine cache fix. Simulator content and settings are separate from Derived Data. If an issue occurs only in one simulator, try restarting that simulator or testing another device first. Erasing a simulator removes its apps and stored data, so use that option only when it directly addresses the problem.
Similarly, do not remove archives or exported app builds unless you intend to discard them. Archives may be needed for distribution, debugging, or release records. They are not the same thing as the everyday build cache.
What to Do If Clearing the Cache Does Not Work
If your app still fails to build after a clean, work through the problem in a controlled way rather than repeatedly deleting folders.
- Read the first meaningful error in the build log; later errors may be consequences of it.
- Confirm that the selected scheme, build configuration, and destination are correct.
- Check whether the issue happens in a new build or only when running on a particular simulator or device.
- Resolve package dependencies again if the error involves Swift packages.
- Restart Xcode and, if necessary, restart your Mac to release stuck processes.
- Check that the installed Xcode version supports your project’s Swift version and target platform.
- Search the project for recent changes to build settings, scripts, signing, or dependency versions.
When reporting a persistent issue, include the Xcode version, macOS version, selected scheme, and the complete relevant build error. These details help distinguish a stale cache from a configuration or dependency problem.
Conclusion
To clear the Xcode build cache, first try Product > Clean Build Folder. If the problem remains, delete the affected project’s Derived Data through Xcode’s Locations settings or Finder. Use Terminal only if you are comfortable checking the path carefully, and reset Swift Package Manager caches only when the problem involves dependencies.
Once the cache is cleared, rebuild the project and allow Xcode time to recreate its generated files. These steps often resolve stale build products and indexing issues, while keeping your source code and important archives intact.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.