Understanding and Managing Xcode Space
Learn how to free up space hogged by Xcode in caches, derived data, archives and simulators! By Keegan Rush.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Understanding and Managing Xcode Space
20 mins
- Getting Started
- Clearing Derived Data
- When to Delete Derived Data
- Deleting Derived Data
- Clearing Archives
- Archiving Stellar Space
- Clearing the Archived Build
- When to Clear Archives
- Clearing Simulators
- Storing Simulator Data
- Erasing Simulator Content
- Deleting Unavailable Simulators
- Device Support
- Finding Device Support Files
- Other Platforms
- Caches
- Supporting Caches
- Tying it All Together
- Creating a Script
- Running the Script
- Where to Go From Here?
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.
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. :]
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.
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
Click Go to change the Finder window’s path to DerivedData.
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.
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.
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:
- In the Project navigator, select Stellar Space.
- Select Stellar Space under Targets.
- Select the Signing & Capabilities tab.
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.
You can’t archive an app when building for a simulator, so change the run destination to Any iOS Device (arm64):
Now, you’re ready to archive the app. From Xcode’s menu bar, select Product ▸ Archive.
If prompted, enter your macOS user’s password:
When Xcode finishes building, the Archives window will open with the result.
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
Click Go.
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.
Right-click the .xcarchive and select Move to Trash.
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?