How to Delete Derived Data and Clean Project in Xcode 5 and Later

How to Delete Derived Data and Clean Project in Xcode 5 and later?

It's basically a two-or-three-step process, which cleans the project of all cached assets.

Of course, if anyone uses this technique, and a project still does not show updated assets, then please add an answer! It’s definitely possible that someone out there has encountered situations that require a step that I’m not including.

  1. Clean your project with Shift-Cmd-K
  2. Delete derived data by calling a shell script (details below), defined in your bash profile
  3. Uninstall the App from the Simulator or device.
  4. For certain types of assets, you may also have to reset the Simulator (under the iOS Simulator menu)

To call the shell script below, simply enter enter the function name (in this case 'ddd') into your terminal, assuming it's in your bash profile. Once you've saved your bash profile, don't forget to update your terminal's environment if you kept it open, with the source command:

source ~/.bash_profile

ddd() {
#Save the starting dir
startingDir=$PWD

#Go to the derivedData
cd ~/Library/Developer/Xcode/DerivedData

#Sometimes, 1 file remains, so loop until no files remain
numRemainingFiles=1
while [ $numRemainingFiles -gt 0 ]; do
#Delete the files, recursively
rm -rf *

#Update file count
numRemainingFiles=`ls | wc -l`
done

echo Done

#Go back to starting dir
cd $startingDir
}

I hope that helps, happy coding!

How can I delete derived data in Xcode 8?

Many different solutions for this problem. Most of them work as well.
Another shortcut seems to be added as well:

Shift + alt + command ⌘ + K

Will ask you to:

Are you sure you want to clean the build folder for “MyProject”?

This will delete all of the products and intermediate files in the build folder.

In most cases this would be enough to solve your problems.

UPDATE

As of Xcode 9 you'll be able to access the Derived Data folder by navigating to

File -> Project Settings

or if you use a Workspace:

File -> Workspace Settings

And press the arrow behind the path:
Sample Image

How to Delete derived data in Xcode?

Pressing Cmd + Shift + 2 In Xcode 6 will present Devices, which is separated from Organizer. Instead you can go Window, then Organizer, then find your project in Projects to delete derived data. You may set a short key in Key Bindings for quick access to derived data.

Sample Image

How to Delete derived data in Xcode8?

  • Close Xcode
  • Open Terminal and enter this command

    rm -rf ~/Library/Developer/Xcode/DerivedData

Can I safely delete contents of Xcode Derived data folder?

Yes, you can delete all files from DerivedData sub-folder (Not DerivedData Folder) directly.

That will not affect your project work. Contents of DerivedData folder is generated during the build time and you can delete them if you want. It's not an issue.

The contents of DerivedData will be recreated when you build your projects again.

Xcode8+ Update

From the Xcode8 that removed project option from the window tab so you can still use first way:

Xcode -> Preferences -> location -> click on small arrow button as i explain in my first answer.

Xcode7.3 Update
For remove particular project's DeriveData you just need to follow the following steps:

Go to Window -> Project:

Sample Image

You can find the list of project and you can either go the DerivedData Folder or you can direct delete individual Project's DerivedData

Sample Image


I am not working on Xcode5 but in 4.6.3 you can find DerivedData folder as found in the below image:

Sample Image

After clicking on Preferences..

Sample Image

You get this window

Sample Image

Xcode won't remove Derived Files

It is ok to delete DerivedData folder, you can delete all files from DerivedData sub-folder (Not DerivedData Folder) directly.

That should not take any effect. Contents of DerivedData folder is generated during the build time and you can delete them if you want. It's not a issue.

All contents of DerivedData will be recreated when you build your projects again.

I suggest you clean project project and build again, ALSO PLEAE MAKE SURE YOUR DELETED DerivedData folder is not in BIN please clean trash, it is important

When can I safely delete Xcode DerivedData folder?

Sadly, deleting DerivedData has become the catch all to try and remedy build issues. As you already know, you can delete the DerivedData at any point in time with no issues (unless of course you were building). The nuances as to when it is safe is a little more complicated. In practice I have generally found that significant changes in the code between builds can have issues. Likewise, changing Xcode versions can also have issues. The key words here being can, which does not mean it will.

I do not believe there is any definitive means of knowing when to purge, which is why I think you find most people generally asking "did you remove DerivedData" as one of the first questions when someone has a build problem.

IMHO, I think there is some subtle caching that Xcode does within DerivedData, as I've had build failures in weird situations I could not trace. I would not be surprised if Xcode has some subtle bug related to this caching. In general, I only trusted a command line delete of the project's DerivedData. And if I was extra careful, I'd also purge any associated libraries/frameworks as well as the ModuleCache (in DerivedData). There is also some voodoo in the /var/folders. Not sure if this is still the case, but I have found myself surgically nuking stuff there. Yeah, bad. But I'm also the kind of person that has been known to edit the project.pbxproj file to fix it, so I guess I throw caution to the wind.

Let me ask you this question. What is more important? "bullet-proof" or build times? I've been roped into maintaining or upgrading the build systems for a few apps. I've always done everything as a clean build. This always was fresh pull from source control and then having a defined DerivedData within the workspace (these were Jenkins builds and was configured to use a clean workspace). This pretty much avoided build issues related to needing to remove DerivedData. I've seen way too many strange issues occur due to some Xcode voodoo. It is far better to not add red herrings if you have a build error.

If you do find that the builds as well as any tests needed are taking too long, you can start to devise other strategies to help make it more manageable. This becomes very project dependent. For example on a project I was working on, I moved all libs to pre-built versions. For some reason, they had it setup where they had to build all the 3rd party libs (like openssl) during the build process. This also means that the devs incurred this build penalty the first time they built or any time the cleaned.

How to Empty Caches and Clean All Targets Xcode 4 and later

Command-Option-Shift-K to clean out the build folder. Even better, quit Xcode and clean out ~/Library/Developer/Xcode/DerivedData manually. Remove all its contents because there's a bug where Xcode will run an old version of your project that's in there somewhere. (Xcode 4.2 will show you the Derived Data folder: choose Window > Organizer and switch to the Projects tab. Click the right-arrow to the right of the Derived Data folder name.)

In the simulator, choose iOS Simulator > Reset Content and Settings.

Finally, for completeness, you can delete the contents of /var/folders; some caching happens there too.

WARNING: Deleting /var/folders can cause issues, and you may need to repair or reinstall your operating system after doing so.

EDIT: I have just learned that if you are afraid to grapple with /var/folders/ you can use the following command in the Terminal to delete in a more targeted way:

rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"

EDIT: For certain Swift-related problems I have found it useful to delete ~/Library/Caches/com.apple.dt.Xcode. You lose a lot when you do this, like your spare copies of the downloaded documentation doc sets, but it can be worth it.

Difference between cleaning and deleting the DerivedData folder

This is explained in User Your Loaf's article on Xcode 4 DerivedData and Cleaning the Build Directory.

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.

DerivedData on the other hand contains other stuff:

Each workspace gets a unique set of symbol indexes, build products, window layouts, etc., otherwise referred to by Xcode as derived data.

So, the answer if you want to really clean everything, is to use the new Xcode 4 Clean Build Folder action by selecting the Product menu whilst holding the Option key. That will also delete the DerivedData contents:

Sample Image



Related Topics



Leave a reply



Submit