How to clean your Xcode environment

How to clean your Xcode environment

Β·

2 min read

From time to time, it’s a good idea to clean up your working space 🧹

Cleaning has a collateral effect to free up valuable space on your Mac as you can see below. The last time I could save almost 17GB of space.

I regularly do some clean up and I advise you to do so, those folders tend to grow in size quite quickly.

clean Xcode.png

Clean your build folder and module cache

You can accomplish this in two ways:

  • Choose Product β†’ Clean ( get rid of the current build and create a new one next time you run the code) or press Command + Shift + K.

  • Choose Product β†’ Clean Build Folder (removes the build folder for the project) or press Command + Shift + Option + K.

Delete the contents of your DerivedData folder

  • Or quit Xcode, open your user ~/Library/Developer/Xcode/DerivedData folder ( tip: you can use the shortcut Shift-Command-G in Finder), and move the contents of the DerivedData folder to the trash.

In Terminal you can open the folder as well with:

open ~/Library/Developer/Xcode/DerivedData

Or delete from the Terminal, but be extra careful with that! πŸ˜…

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

Remove older iOS versions

In Xcode, open your user ~/Library/Developer/Xcode/iOS DeviceSupport folder and check in the folder if you need all these versions! One operating system can be up to 4GB!
However, here the system keeps track of the Symbols and you will need them when you connect to a hardware device like iPhone or iPad. So look at the folders and you will see that they are corresponding at the toolchains which have been installed in the past. I advise to delete only the ones you don't need anymore.

In Terminal you need to escape the space:

open ~/Library/Developer/Xcode/iOS\ DeviceSupport

good tip to free up memor.png

Remove unavailable simulators

Open the Terminal and type:

xcrun simctl delete unavailable

Remove your app from the Simulator

This is useful because when a new build of the app is copied to the Simulator, existing resources inside the old build may not be removed, and this may cause the app to behave oddly.

Choose Hardware β†’ Erase All Content and Settings.

To go all the way and clean out all simulators, quit the Simulator and then type, in the Terminal:

xcrun simctl erase all

I hope this could be useful. If so please let me know in the comments!

Sources:

StackOverflow and Twitter! Kudos to this Donny Wals tweet for inspiration!