Jonathan suggest here: Xcode Includes .xib files that have been deleted! that cleaning all targets and empty the caches will fix the problem with Xcode including deleted .xi
I found another way in addition to command+option+shift+K. In XCode 4.2 there is an organizer that can be opened from top-right icon. You can clean all archives and saved project options from there. This helped my situation (I was seeing old removed files in the mainBundle).
Command-Option-Shift-K to clean out the build folder. Even better, quit Xcode and clean out ~/Library/Developer/Xcode/DerivedData manually. Remove all its contents because there's a bug where Xcode will run an old version of your project that's in there somewhere. (Xcode 4.2 will show you the Derived Data folder: choose Window > Organizer and switch to the Projects tab. Click the right-arrow to the right of the Derived Data folder name.)
In the simulator, choose iOS Simulator > Reset Content and Settings.
Finally, for completeness, you can delete the contents of /var/folders; some caching happens there too.
WARNING: Deleting /var/folders can cause issues, and you may need to repair or reinstall your operating system after doing so.
EDIT: I have just learned that if you are afraid to grapple with /var/folders/ you can use the following command in the Terminal to delete in a more targeted way:
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
EDIT: For certain Swift-related problems I have found it useful to delete ~/Library/Caches/com.apple.dt.Xcode. You lose a lot when you do this, like your spare copies of the downloaded documentation doc sets, but it can be worth it.
To delete all derived data and the module cache in /var/folders
use this little ruby script.
derivedDataFolder = Dir.glob(Dir.home + "/Library/Developer/Xcode/DerivedData/*")
moduleCache = Dir.glob("/var/folders/**/com.apple.DeveloperTools*")
FileUtils.rm_rf derivedDataFolder + moduleCache
This just solved a fatal error: malformed or corrupted AST file: 'Unable to load module "/var/folders/
error for me.
Command-Option-Shift-K should do it. Alternatively, go to product menu, press the option key, now the option "Clean" will change to "Clean Build Folder ..." select that option.
When using a "Data Model" , there are options in the inspector to generare classes, for me this was the case as there was already a class with the existing name.
Codegen: solved it for me.
I had some problems with Xcode 5.1 crashing on me, when I opened the doc window.
I am not sure of the cause of it, because I was also updating docsets, while I opened the window.
Well, in Xcode 5 the modules directory now resides within the derived data folder, which I for obvious reasons didn't delete. I deleted the contents of ~/Library/Developer/Xcode/DerivedData/ModuleCache and the ~/Library/Preferences/com.apple.Xcode.plist and everything then seems to work, after I restarted Xcode.