Created
July 25, 2020 00:43
-
-
Save arthurdapaz/e2a4fc83fa561ec52af83a5b08d0497d to your computer and use it in GitHub Desktop.
Safely Reset Xcode from 9.3 to 11.6. Clean, clear module cache, Derived Data and Xcode Caches.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
############ | |
### zsh script to clear xcode caches and project | |
### | |
### Works from Xcode 9.3 to Xcode 11.6 | |
### | |
### last date I tested: (7/24/2020) | |
### | |
### Move this script to /usr/bin/local so this will be the default usage: | |
### cd myXcodeWorkspace/ | |
### xclean | |
### | |
############ | |
# clean up function | |
function cleanXcode() { | |
setopt nomatch | |
pkill -int com.apple.CoreSimulator.CoreSimulatorService | |
killall Xcode | |
xcrun -k | |
xcodebuild -alltargets clean | |
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache" | |
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache" | |
rm -rf ~/Library/Developer/Xcode/DerivedData/* | |
rm -rf ~/Library/Caches/com.apple.dt.Xcode/* | |
xed "$TARGET" . | |
} | |
# ensures that you are inside a Xcode folder | |
function ensureFolder() { | |
local workspace project return variable=$1 | |
workspace=(*.xcworkspace) | |
project=(*.xcodeproj) | |
if [ -e "${workspace}" ] || [ -e "${project}" ]; then | |
return=true | |
else | |
return=false | |
fi | |
eval $variable="'$return'" | |
} | |
# script main entry point | |
unsetopt nomatch | |
ensureFolder contains_xcode_project | |
if $contains_xcode_project; then | |
echo "✓ Cleaning Xcode..." | |
cleanXcode | |
else | |
echo "⨯ Xcode workspace or project not found" | |
fi |
Great! Worked for me
Hi Arthur
When I run xclean.sh, i get this message : xCode workspace or projet not found
Can you help me ?
Pascal
The script is pretty self explanatory. I made it to work with zsh (shell), if you want to use safely with other shell, you need to change the firstline of the script. But if you have zsh installed it should run just fine.
After that, just make sure that you are indeed inside a folder which contains a workspace or a xcodeproject (or both) and run the command
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Arthur
When I run xclean.sh, i get this message : xCode workspace or projet not found
Can you help me ?
Pascal