Understanding and Managing Xcode Space

Learn how to free up space hogged by Xcode in caches, derived data, archives and simulators! By Keegan Rush.

Leave a rating/review
Download materials
Save for later
Share

Xcode is more than a plain old text editor. It’s a full-blown Integrated Development Environment (IDE).

Using an IDE for iOS development comes with myriad benefits. Xcode makes it easy to build projects, debug them and code-sign the resulting app.

But all the functionality provided by an IDE takes up space in your Mac’s storage. A fresh installation of Xcode takes 11 gigabytes on your Mac. But those 11 gigabytes are just the tip of the iceberg. For all its good qualities, Xcode is a notorious storage hog.

Xcode the space hog

Over time, Xcode’s storage size bloats when considering some of its tools and directories:

  • Derived data
  • Caches
  • Old archives
  • Unavailable simulators
  • Device support files

To make matters worse, this saved data doesn’t only eat into your Mac’s precious storage. It can also be a source of strange bugs and compilation issues.

If you see strange behavior when building an app, clearing folders such as derived data and caches can help to restore normality. Even Xcode needs a bit of spring cleaning sometimes. :]

Note: You need to be careful when deleting Xcode’s data on your Mac. Don’t delete anything unless you’re sure Xcode will work fine without it. This tutorial will give you the know-how of when and why to delete some of Xcode’s supporting files.

In this tutorial, you’ll learn more about the purpose of each directory and why you might want to clear it.

Once you understand what each directory does, you’ll write a script to help keep your Mac in tip-top shape.

So get ready to reclaim some long-lost Mac storage!

Getting Started

First, download the project materials by clicking the Download Materials button at the top or bottom of this tutorial. Then, open the starter project in Xcode. Make sure to choose a simulator as the build target, then build and run.

Stellar Space

Using NASA’s Astronomy Picture of the Day API, Stellar Space shows images taken by NASA for users to choose and save to their device.

Images saved to your iOS simulators use storage on your Mac. Clearing that storage is one of the things you’ll learn in this tutorial.

Earlier, when you built Stellar Space, Xcode saved some caches and build files. Next, you’ll clear it up.

Clearing Derived Data

When you build a project, Xcode stores build files for that project in your derived data. You’ll find your derived data folder in your macOS user library.

To find your derived data folder, open a new Finder window. In the Finder menu bar, select Go ▸ Go to Folder….

Here, type the location of your derived data folder:

~/Library/Developer/Xcode/DerivedData

Go to Derived Data

Click Go to change the Finder window’s path to DerivedData.

Derived data folder

Your derived data contains a ModuleCache.noindex folder as well as folders for any projects you’ve built in Xcode, such as Stellar Space.

ModuleCache.index stores modules that Xcode compiled earlier. Xcode shares these cached modules between projects and builds to quicken build time.

Similarly, the individual project folders also quicken build time. In the Stellar Space folder, you’ll find supporting files that Xcode generated the last time you built Stellar Space.

When to Delete Derived Data

Everything in DerivedData is safe to delete. In fact, clearing derived data is a common trick among iOS developers to sort out pesky compilation issues.

Although deleting derived data is safe, your build will take a little longer next time while Xcode builds your project from scratch.

Deleting Derived Data

Clearing your derived data is as simple as deleting the entire folder from Finder. Next, you’ll delete only the Stellar Space folder, in case you want to keep the data for any other apps that have particularly long build times. :]

In your Finder window, look for Stellar Space’s derived data.

Stellar Space's derived data

Mine is named Stellar_Space-gmjdilbusvnhawfcpcbkkdqfsiuv, but yours will be different.

Right-click the Stellar_Space folder and select Move to Trash to delete it.

Note: Depending on the language settings on your Mac, the menu option may say Move to Bin or some other localized option.

With that, you’ve cleared the derived data for Stellar Space. Remember: To delete all your derived data, you need to delete the entire DerivedData folder.

This clears up the debug version of Stellar Space that you built. But archived release versions are stored elsewhere.

Clearing Archives

Whenever you archive an app for distribution on TestFlight or the App Store, that archive is stored locally on your Mac. You could have years-old archives waiting to be cleaned up.

In this section, you’ll archive Stellar Space and then remove that archive from your Mac, saving valuable storage space. But first, you need to prepare Stellar Space for code-signing.

Archiving Stellar Space

In Xcode, follow these steps to reach the Signing and Capabilities settings for Stellar Space:

  1. In the Project navigator, select Stellar Space.
  2. Select Stellar Space under Targets.
  3. Select the Signing & Capabilities tab.

Stellar Space's signing and capabilities settings

Currently, the Team used to archive Stellar Space is set to None. Change the value for Team to that of your own Apple Developer account.

Empty Team value

Note: If you don’t have an Apple Developer account you can use here, don’t worry. You can read on without archiving Stellar Space.

You can’t archive an app when building for a simulator, so change the run destination to Any iOS Device (arm64):

Run destination set to Any iOS Device

Now, you’re ready to archive the app. From Xcode’s menu bar, select Product ▸ Archive.

If prompted, enter your macOS user’s password:

Enter your password for codesigning prompt

When Xcode finishes building, the Archives window will open with the result.

Xcode Archives window

Xcode created your archive. The actual .xcarchive folder resides on your Mac in ~/Library/Developer/Xcode/Archives.

Clearing the Archived Build

To open the archives folder, open a Finder window. In the Finder menu bar, click Go ▸ Go to Folder…, and type in the path to your archives folder:

~/Library/Developer/Xcode/Archives

Go To Archives folder in Finder

Click Go.

Archives folder

Each archive is stored in a subfolder named for the day when you created it. Open today’s folder to see the Stellar Space archive that you made earlier.

Today's archives folder

Right-click the .xcarchive and select Move to Trash.

Today's archives folder after deletion

You’ve deleted the archive, saving a modest amount of disk space. But there could be gigabytes worth of .xcarchives in the archives folder. When is it safe to clear them?