Sometimes Xcode can get in an odd state, and in most cases cleaning your derived data folder has the highest success rate to any Xcode related problems. Depending on your Xcode version this solution may be required a lot and his handy tool will allow you to quickly clear derived data by opening an app your spotlight.
Download and extract the .zip anywhere on your Mac. I recommend putting the app in your Applications folder or I found it useful placing it in my iCloud documents folder. So the app would be synced over my Macs.
The app has 2 versions, the first one stays open with a list of all the deleted files then waits for you to click Quit. The autoclose version will just close when it’s done cleaning.
Extract the .app in your applications folder. CMD+Space and type “dele…”. The app should instantly popup and enter to start the cleaning. The app will show a list of all files being deleted ending with done when all your derived data is removed. Simply click Quit to close the screen, or download the autoClose version that will automatically close when the derived folder is cleaned. The deleted files will skip the trash and will be permanently deleted.
The app will show the list of files it has deleted and
note: This app will simply run “rm -rf” on the documents folder (~/Library/Developer/Xcode/DerivedData), if you configured a different location in Xcode, this script will not work and the correct setting is shown in the image below.