Have you seen this error message before? Perhaps the last 200 times you’ve tried to open Xcode?
It’s usually followed by its loveable companion, the crash report window. The one where you can enter a comment that nobody at Apple will ever read or respond to:
This is a peculiarity that can happen with a particular project. To avoid the first message, select the option “Don’t reopen windows”. This will bring up the Xcode welcome screen. The second message (the almighty Crash Reporter) may still come back to haunt you when you open a particular project – and only that project.
Looks like that project has a problem.
There is usually a way to fix this by deleting the xcuserdata file from the project. This is one of the most annoying features for version control: this set of files keeps track of which tabs/windows are open, which groups are expanded, which methods are collapsed, and in general how your project looks like when you left it.
The trouble is of course that this file changes every 0.000001 seconds, so every time you make a git commit it’s almost instantly outdated. The implication is that you can’t switch to or merge a branch. If you go ahead and mess with this file outside of Xcode problems can arise – usually resulting in us developers wanting to take up another hobby or calling our therapist.
How to fix this
To fix this problem:
- open a Finder window and navigate to your project
- right-click on the .xcodeproj file (it’s a package actually)
- select Show Package Contents
- a new window appears
- delete a folder called xcuserdata
Now open your project again in Xcode and it should work. Your workspace will be reset, bringing a very small amount of happiness and tranquility back into your life.
Until this problem happens again.
How to avoid this in the future
In an ideal world those xcuserdata files should all be ignored by Git. And in an ideal world we should never need to use external version control tools like the command line or GitHub for Mac.
Sadly the version control tools in Xcode are far from perfect which means that we have no other choice. You can use your external tool to ignore these files of course, but adding them to a .gitignore is not enough to make them disappear retrospectively or in other branches.
Here’s how to do that: once added to .gitignore, you must issue the following command:
git rm --cached ProjectFolder.xcodeproj/project.xcworkspace/xcuserdata/yourUserName.xcuserdatad/UserInterfaceState.xcuserstate git commit -m "Removing file thats driving me insane"
This may restore some order to your project.