This article has some way to clean/reset Xcode data/settings, which may lead to fixing your Xcode crashes, unwanted project errors, etc. The following steps are master reset for your Xcode, follow these steps in sequence, and after each step check whether the problem is solved or not.

1. Clean Build Folder

This will delete all of the products and intermediate files in the build folder. To clean the build folder you can use the shortcut Command + Shift + K or Menu Bar → Product → Clean.

2. Delete Derived Data

By deleting derived data Xcode will recreates Derived Data when it indexes your files. You can delete device data by running the following command in the Terminal:

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

3. Delete Swift Package Manager (SPM) Caches

If you are using SPM, then you can try to delete the Swift Package Manage Caches by running the following command in the Terminal:

rm -rf ~/Library/Caches/org.swift.swiftpm

4. Delete CoreSimulator Caches

Run the following command to delete various kinds of caches generated by simulator (like Xcode SwiftUI Preview caches):

rm -rf ~/Library/Developer/CoreSimulator/Caches

5. Reset the Simulator Content and Settings

This will delete all installed applications, content, and settings. To reset the simulator launch the iOS Simulator and then go to the Menu Bar → Device → Erase All Content And Settings. You can also run the following command to erase content and settings for all simulators.

xcrun simctl erase all

6. Delete Xcode Preferences

This is our final step to fix Xcode crashes by resetting Xcode's preferences. Run this command in your terminal:

defaults delete com.apple.dt.Xcode