SwiftUI Previews - Disk space issue

I'm seeing a lot of disk space (e.g. over 20 GB ) taken up by SwiftUI previews under this folder:

~/Library/Developer/Xcode/UserData/Previews

Arbitrarily deleting the contents of this folder seems to stop previews from working.

xcrun simctl delete unavailable does not seem to work on this folder, as well.

There is a device_set.plist file in the Simulator Devices sub-folder, and some of the sub-folders are not listed in this file.

In general, has anybody figured out a safe way to cleanup this folder or heard from an Apple engineer on what exactly goes on in there?

Does Xcode actually manage the contents of this folder by adding / deleting devices when you add / remove simulator runtimes?

Post not yet marked as solved Up vote post of handmadeapps Down vote post of handmadeapps
5.1k views
  • Suggested by an Apple Frameworks engineer: xcrun simctl --set previews delete all My Previews folder was 110GB and went to 6GB. Everything seems to be working well.

Add a Comment

Replies

To clean it up I do the following...

I quit Xcode, delete that directory and load Xcode and previews work.

  • This is not working on my system. As mentioned, the deleted folder is not recreated and SwiftUI previews report missing simulator devices.

Add a Comment

So, apparently there is an xcrun invocation that handles this:

xcrun simctl --set previews delete unavailable | all

This correctly cleans up the folder without crashing the Previews.

That does'n work for me, terminal says Using Previews Device Set: '/Users/mcrich/Library/Developer/Xcode/UserData/Previews/Simulator Devices'

  • I have also tried the following command, but I get an error and can't figure out the solution. The directory referenced is /var/root/ and I am assuming this is the cause.

    sudo xcrun simctl --set previews delete unavailable Using Previews Device Set: '/var/root/Library/Developer/Xcode/UserData/Previews/Simulator Devices' Provided set path does not exist: /var/root/Library/Developer/Xcode/UserData/Previews/Simulator Devices`

Add a Comment

the Previews folder is taking up 165 GB of my disk and the size is increasing every day, it is insane. Did anyone find a solution for this?

I created a virtual drive on an external drive and made an apple script to close xcode and its programs, mount it in the correct spot, and re-open xcode.