I’m on page 58 of the second edition of Erica Sadun’s “iPhone Developer’s Cookbook,” and here are the most important lessons I’ve learned so far:

  1. Zombies!
  2. What’s inside that XIB?
  3. The Clear Log Button

Setting NSZombieEnabled to YESZombies!
Did you know that, by default, your XCode project is NOT enabled to catch Zombies?  And by zombies, I mean objects that you have released, but then subsequently try to access?  THEY ARE ZOMBIES! They are the dead that still roam.  This is good for horror films, but very bad for your code.  But, by default, XCode’s debugger has no way to catch these nasties.

If you try and access a destroyed or released object, you’ll get back a cryptic objc_msgSend.  But!  If you ENABLE THE ZOMBIES as Sadun suggests, you’ll get back a much better message. In my case, I’m trying to access an array (via this call: CFShow([array self])) that I’ve already released. This gives me the following message in my gdb console:

2010-03-30 21:39:28.180 HelloWorld2[2398:207] *** -[CFArray self]: message sent to deallocated instance 0x1810260

interfacebuilderGetting inside those .xib files

I have long been troubled by the question, “What code is generated by Interface Builder?” One of the things I really liked about the .NET platform is that when you created in the Designer, code was generated. You could double-click a button, and Visual Studio would automatically create event code to handle the button click. Not so with the .xib files that Interface Builder generates.

You can look at the XML Interface Builder creates by simply opening the file in Text Edit, as Sadun points out. (The actual command would be open -e filename.xib). This much I knew. What I didn’t know, was that a beloved member of the iPhone community, WHO I ALREADY FOLLOW ON TWITTER, akosma, has written a utility called nib2objc that allows you to see exactly what code Interface Builder is generating. FAIL for me. WIN for @akosma!

Clear LogClear that Console

Another thing I’ve found annoying about XCode is how cluttered the Console gets. I am constantly clearing the console, and the button is not ideal. So, I took Sadun’s two suggestions, and (1) moved the “Clear Log” button from all the way on the right to closer to the middle of the window (do this by right-clicking the toolbar and clicking Customize), and (2) re-mapping the keyboard shortcut for “Clear Log” from the cumbersome, Control-Option-Command-R to one that I like, Command-D. This overwrites the “add bookmark” keymapping, but I never use that anyway.

NEXT UP! My first recipe on page 62.

No Responses to “Zombies, demystifying the XIB, and console clearing: iPhone Cookbook Lessons”  

  1. No Comments

Leave a Reply