A couple times now I’ve had compilation errors in Xcode.
The first was when I started Tutorial #2 immediately after doing #1. Because I had removed the launch screen storyboard in BullsEye, my Checklists project wouldn’t compile. I was pulling my hair out trying to figure out why, and tried “Clean and Build” which fixed it.
While working on the Checklists project, when I made a change to the AddItemViewControllerDelegate protocol, Xcode insisted that there was an error in the delegate class even after all was correct. I spend quite a long time trying to figure out where my typographical error might be, to no avail. Finally I tried Clean and Build and that fixed it.
So… WHY? What’s going on here with Xcode? Can anyone explain to me so I can better predict when “Clean and Build” might help and when to keep looking for my own errors in the code?
I don’t know that this is the answer, so I’m happy to be corrected by others.
Xcode is an IDE written not just to compile your code into a working app, but to help you write correct code. So, simultaneously with you typing, it parses the code you’ve written and builds up a model of it - for example, building up lists of properties and function names so it can autocomplete what you’re typing, figuring out which cases of an
enum you’ve already accounted for in your
switch statement so it only offers you the remaining cases, and so on. It’s not an intensive process, because Xcode shouldn’t be unresponsive while you’re typing, but it should highlight relatively obvious errors / warnings.
However, when you change something in code, Xcode can’t retrace its steps perfectly. So, you’ve changed one function declaration in a protocol, and Xcode will work with that, but it can’t immediately find every type which used to conform to the protocol and now doesn’t, or it doesn’t re-infer an inferred type, or some other consequence… the data model is based on assumptions which are no longer true and without starting again from nothing, it can’t find all the invalid parts of the model.
Clean and build clears away the data model. Another, more intensive, data model exists as your project’s ‘derived data’. Or, this is what I think they are.
Could you send the tutorial’s Source Code folder of the book of IOS APPRENTICE to me?
Thanks a lot!
@slowmouse: if you bought the PDF (or PDF & physical copy) from the Ray Wenderlich site, you can download the source code folder from your Loot page. If you only have the physical copy, read the Introduction to the book; you should find a link to download from there.