30 May 2011

Exception

So there I was, mucking about in Xcode, following along with an example in that book I've been studying (trying to determine why the keyboard wouldn't hide when I touched outside a text field). In the spirit of (reckless) experimentation, I tried adding an Outlet to the top level View of a View Controller, dragging into the Header file to automagically create it. I knew almost at once this wouldn't be what I wanted, and I deleted the reference in Interface Builder, and the code it had added to the other files.

But when I ran the program, it threw an exception. Being so new to all this, I didn't think to check the log files, and when I couldn't work out what the error was (or fix it), I gave up, restored an earlier version of the project from Time Machine, and tried again — same result. I restored an even earlier version and tried again — and got the same error!

When I finally had the good sense to have more than a passing glance at the log file, I noticed the reference to the name of the Outlet I had added, but removed! But these were older versions of the code, before I'd even made that change.

I made a thorough search of the code, and my NIB file, looking for any reference to the deleted Outlet. I couldn't find it anywhere.

I eventually replaced the NIB file with a version from the tutorial from the book I was following (it was identical, and easier than rebuilding it from the bottom up), and all was well, everything ran just fine. But now I'm left wondering -- what could I have done to make this error so persistent, across different versions of the file? I'm already kinda uncertain about the way Xcode 4 will automagically add code under certain circumstances — that's probably more dangerous than useful for the novice.

I find I'm learning the most when I'm making the most mistakes. Not so much this time, though. This was just bewildering.

No comments:

Post a Comment