Solve most of your Xcode problems through Cargo Cult
If you are an iOS or macOS developper, you probably work with Xcode. And if you work with Xcode, you've most probably had some weird times where, suddenly, things just stopped working.
The "index" would "prebuild" for hours, eating up your CPU.
Syntax highlighting and autocompletion would just abruptly be dropped, leaving you scratching your head in the middle of calling a method.
The project just would not build, because of some phantomatic build error.
Heck, sometimes, Xcode would just crash when opening a project! (and take it's time before displaying anything).
"Solving" this usually involves what some iOS developpers (or, at least, I) call the "rain dance"! Thing is, this actually designates a whole group of different semi-"Cargo cultish" rituals that, more often than not, "solve" most of Xcode's issues.
Personally, I've started to loose track of all the ways to "solve" Xcode's randomly occuring quirks. I've therefore decided to write them all down somewhere. And if I am to write them down, why not share it? So here we are!
Xcode's mysterious cargo cult rituals
Rain dance
- Clean project (Shift + ⌘ + k)
- Close Xcode
- Reopen Xcode
- Eventually clean the project again
This one is a classic, and it can solve many things, some of the time.
Voodoo ceremony
- Close Xcode
- Open your terminal
- Wipe out the Derived Data (
rm -rf /Users/elfitz/Library/Developer/Xcode/DerivedData
) - Reopen Xcode
Pros: solves almost all problems
Cons: if you use Swift Packages, they'll be gone
Invoke the ancestors' spirits through the sacrifice of a pound of dandelions
- Close Xcode
- Open the project's folder.
- If you use a workspace, on the .xcworkspace file, show package content, delete xcuserdata.
- Repeat with .xcodeproj.
- Reopen Xcode.
Reference: https://stackoverflow.com/a/4456229/7243001
Can also be done via the command line (just cd
into the .xcworkspace and .xcodeproj folders).
Banish Little Timmy back to whence he came
If you are using Xcode 12.x, you might be having issues with Xcode randomly hanging very often. It might be caused by Xcode being connected to your devices, either via USB or the network.
- Disable "Connect via network" for your devices
- If you have devices plugged in, unplug them.
Xcode will immediately stop hanging, albeit will sometimes crash ¯\_(ツ)_/¯
Reference: https://developer.apple.com/forums/thread/669378)
Summon the devil (may or may not cost you your soul)
Given the StackOverflow author's warning, I really wouldn't recommend it. But, you do you. It's just included here for reference, and in case I might need it some day.
Reference: https://stackoverflow.com/a/6247073/7243001
Reboot
A great, timeless, Classic. The only way to solve some cryptic permission issues that randomly pop up at build time and then won't go away.
Epilogue
And here you are. Xcode, an evil yet, sometimes, somehow, beautiful voodoo artefact from another eon has turned you into a pagan practicing unholy rituals, damning your soul for all eternity ¯\_(ツ)_/¯
Also, for those of you scratching their heads at the expression cargo cult, it's an actual thing that I definitively haven't made up.
Joking aside... I honestly may just make a Swift cli tool out of this.