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

与世无争的帅哥 提交于 2019-12-17 15:31:00

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/27976787/how-to-delete-derived-data-and-clean-project-in-xcode-5-and-later

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!