I've seen lots of people (including me) facing the crash with EXC_BAD_ACCESS
with unknown reason. A lot of answers with the solution clean and build the project
marked as correct.
I'm curious why this happens and how clean and re-build fixed it, but it seems people just don't care and go on with clean-build solution.
Here's an example of those EXC_BAD_ACCESS
with clean-build solution.
In my case, I'm facing something as ridiculous as this:
func viewDidLoad() {
super.viewDidLoad()
self.childVC.delegate = self // => Crashed EXC_BAD_ACCESS here. Fixed after clean and build
}
As far as I know, this happened in Swift a lot more usually than Objective-C. Could it be Swift's features?
These are my thoughts:
Once run, if project is not already built then Xcode generates the required build files in:
~/Library/Developer/Xcode/DerivedData/
If the project is not cleaned, either manually or automatically, then the same build files are reused in running apps to reduce consequent build time.
You may have already noticed that Xcode sometimes automatically cleans the build after any major code change. For example, on:
But Xcode still has it's flaws, and sometimes does not clean itself when needed making it possible to run with the, let's say, "broken" build files that eventually give rise to such EXC_BAD_ACCESS
errors.
Cleaning it will clear the old build files and new builds don't have the same problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With