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?

To clean it up I do the following...

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

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'

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.

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.

SwiftUI Previews - Disk space issue
 
 
Q