Xcode keeps expanding all groups in the project navigator
OK, I had had enough of this now and decided to try several things out.
Xcode had got to the stage where the project navigator was just broken. I couldn't collapse (permanently) and groups and I couldn't move files around or anything.
In the end what fixed it was deleting the .xcuserstate
file and restarting Xcode.
I lost my tabs and everything but setting them back up took a couple seconds and everything is working fine now.
I also was experiencing this annoying scenario in Xcode 9.2 where the project groups kept expanding themselves.
To fix it:
First, close your project in Xcode. (Otherwise, Xcode will replenish this file upon closing the project.)
Then delete the following file (or move the file somewhere else):
[MyProject].xcodeproj/project.xcworkspace/xcuserdata/[MyUser].xcuserdatad/UserInterfaceState.xcuserstate
Remember to use the "Show Package Contents" option in Finder.
I wrote a shell script that gets rid of all these garbage files that sometimes make problems in xcode:
printf '\33c\e[3J'
RED=`tput setaf 1`
BLUE=`tput setaf 4`
NOCOLOR=`tput sgr0`
BASEDIR=$(dirname "$0")
path1="prj.xcodeproj/xcuserdata"
path2="prj.xcworkspace/xcuserdata"
echo "${BLUE}[XCode cache files pruner, created by Deya Eldeen Elkhawaldeh]${NOCOLOR}"
echo "REMOVING ${NOCOLOR} $BASEDIR/${RED}$path1${NOCOLOR}"
rm -R "$BASEDIR/$path1/"
echo "REMOVING ${NOCOLOR} $BASEDIR/${RED}$path2${NOCOLOR}"
rm -R "$BASEDIR/$path2/"
echo "${BLUE}Done,${NOCOLOR}"
it's hosted in github, maybe someday I will update it with more features, https://github.com/deya-eldeen/XCodeProjectCleaner
A great shortcut to expand/collapse all Xcode's groups folders is doing cmd + click on any of the group arrow