"Clean" an Xcode project?

Discussion in 'Mac Programming' started by TheBSDGuy, Feb 3, 2016.

  1. TheBSDGuy macrumors 6502

    Jan 24, 2012
    I started noticing our drive space was disappearing at an alarming rate. On checking the size of some of our project directories, even tiny projects are running greater than 800MB.

    Is there some command I can use to "clean" one of these projects after development is done? It looks like a lot of it is from tmp files.
  2. zeppenwolf macrumors regular


    Nov 17, 2009
    > Is there some command I can use to "clean" one of these projects after development is done?

    Well, yes, there is the, er, "Clean" command. In my current Xcode, it's Shift-Command-K.

    Additionally, you might consider doing what I do-- I keep source files and build files completely separate. The default is that XCode creates a "build" directory inside your current project folder, where all your source files are. This makes no sense to me.

    I always adjust my "Build Projects Path" in the Project's Build settings to go to a disposable location; in my case I have an entire partition of the drive devoted to temporary files, so, for MyKillerApp, all build files are generated in "Volumes/temp/builds/MyKillerApp".
  3. weichsel macrumors newbie

    May 23, 2013
    Note that when you hold down the option key while you choose the "Product" menu item, the "Clean" command will become "Clean Build Folder". This will wipe the entire "Build" directory and not only "Product, Intermedidates, etc.".
  4. szymczyk macrumors regular

    Mar 5, 2006
    Apple moved the default build location out of the project folder in Xcode 4. The default Xcode build location is the following directory:


    You shouldn't have to do anything to keep your build files separate from your source files. If you're using a recent version of Xcode and Xcode is using the project folder as the build location, you can change the default build location for new projects from Xcode's Locations preferences. You can change the build location for an existing project by choosing File > Project Settings.
  5. Toutou macrumors 6502a


    Jan 6, 2015
    Prague, Czech Republic
    On a similar note - is this really necessary/is it ok? Ten gigs, that's a helluva IDE.
    Snímek obrazovky 2016-02-04 v 23.28.54.png
  6. Red Menace macrumors 6502

    May 29, 2011
    Littleton, Colorado, USA
    Yeah, that thing is a monster. The biggest chunks are documentation and the iPhone and watch simulators.
  7. TheBSDGuy thread starter macrumors 6502

    Jan 24, 2012
    When I wrote this post I shouldn’t have used the word “clean” in it. Maybe “strip” might be a better word.

    Here’s the problem:

    As an example, we have one project that has a main module and 5 nib files. When we compile all this stuff, the overall size of the main build folder is close to 1GB. The source code isn’t huge, maybe about 500K, and the xib files aren’t huge or overly complicated. When the compiled product is fully assembled into an actual app, the size of it (with all nib/xib files…everything) isn’t too big, maybe about 12MB.

    What I would like to do is completely strip out all the junk leaving the complied app and nib files, source code, xib, and project files, so that when we’re done developing if we ever need to go back and rebuild or update code all we need to do is modify whatever code needs modification and then recompile, and then once a again when done, strip out all the rubbish.

    I’ve tried this with even simple apps, and even they seem to be using close to 800MB of space each.

    If this keeps up we’re going to have to go out and buy a bunch of huge drives just to do basic development. There has to be a better way!

    By the way, thanks for the input so far. It’s given me some ideas.
  8. Red Menace macrumors 6502

    May 29, 2011
    Littleton, Colorado, USA
    As mentioned earlier, current versions of Xcode place the build stuff (which includes various intermediate and debug data) in the DerivedData folder in your user's ~/Library/Developer/Xcode folder, so after testing you can perform an archive build, move the finished product somewhere and then delete the build folder.
  9. chown33 macrumors 604

    Aug 9, 2009
    First you need to discover what's strippable as "rubbish" in your project folders.

    If it's derived data, then edit the project so Xcode puts the derived data outside the project folder. Other posts have already described how to do that.

    If it's not derived data, then you need to dissect one of your project folders, and figure out what's taking up the space. The 'du' command may help. Try this command, replacing PATH_TO_PROJECT with the correct pathname to a project folder.
    If you want an interpretation on what 'du' is telling you, post the complete output (copy and paste from the Terminal window). You can also read the man page for 'du' and interpret the output yourself.

    There are also various GUI tools that can help you find where disk space is being used. Examples include DaisyDisk, OmniDiskSweeper, GrandPerspective, and others.

    Once you know where the rubbish is located within a project folder, you can formulate a command-line to remove it. This could be probably done as an Automator application with a suitable Run Shell Script that removes the "rubbish" items for a project folder dropped on it. If you need help with that, ask again, and make sure to tell us what the sub-folder is where the rubbish is located.
  10. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    That's easy. Put the source code, resources, xib and project files under source control on a remote server (svn, git or maybe even github), build, and copy the resulting compiled app bundle into your Applications directory. Then you can deleted everything, source folder, any build directories or derived data, and have nothing left in your user account (except maybe the app). Check the project out from source control if you need to go back and work on the app. Also, make sure your source repository gets backed-up.
  11. zeppenwolf macrumors regular


    Nov 17, 2009
    "In xcode 4" ?

    Our experiences differ, then. I am using several versions of Xcode, depending on system version, for backward compatibility. But, for example, in Xcode 5.1.1, if I create a brand new project "CiaoWorld", then XCode creates a "build" folder inside the ${Project} folder, which is to say that it creates and uses "CiaoWorld/build/" not to mention "CiaoWorld/CiaoWorldTests"

    In terms of source control, these are nothing more than pollution.

    Well on that we are in agreement. :)
  12. szymczyk macrumors regular

    Mar 5, 2006

    Yes. In Xcode 4. You should go to Xcode's Locations preferences and change the derived data location from Relative to Default if new projects are using the project folder as the build location.

    You may also find the following article helpful:

    Changing Xcode's Build Location
  13. TheBSDGuy thread starter macrumors 6502

    Jan 24, 2012
    What I was hoping for was some command or sequence that I missed that would strip the stuff out. Clearly this needs to be a job done by custom shell scripts, which is what I'll probably do. Thanks to all for the input anyway.

Share This Page