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

2

15

Is there a procedure I can follow that includes running a script in the terminal, to delete all the files under the derived data folder and reliably clean a project?

Sometimes, a project's assets don't always get updated to my simulator or device. It's mostly trial and error, and when I find that an old asset made its way into a test build, it's too late, not to mention embarrassing!

I've looked at this question, but it seems a little outdated: How to Empty Caches and Clean All Targets Xcode 4

I also checked out this question, but I don't want to waste time in Organizer, if I don't absolutely need to: How to "Delete derived data" in Xcode6?

I've looked at other posts out there, but found nothing that solves the problem of reliably cleaning a project and saves time with a script.

Doublestop answered 16/1, 2015 at 3:18 Comment(0)
E
22

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!

Exult answered 16/1, 2015 at 5:32 Comment(3)
Why do you need a script? Just rm -rf ~/Library/Developer/Xcode/DerivedData/*.Recite
Sometimes, one or more files are locked or have some other property that prevents them from being deleted immediately. The script checks for this and retries until it succeeds or is canceled. Also, typing ddd in the terminal is a lot faster than arrowing back to the last rm command in my history, or typing the rm command.Exult
Just quit Xcode before remove files under the directory.Teth
M
1

Another way to delete derived data in Xcode is just by deleting the Derived Data folder. Here is a visual tutorial of how you can do that easily without using command line: https://www.youtube.com/watch?v=ueEMGXKDBAc

Meshwork answered 22/5, 2020 at 21:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.