caveman debugging on ios

Mon, Feb 13, 2012

Coming from Java and a decent IDE, iOS is a bit of shock due to XCode. Take this code for example:

I came up against this when writing real code and the error is obvious when you get that ‘doh!’ moment and remember that the gizmo property is initially nil and needs to be initialised to something, perhaps by a delegate call from a UIActionSheet perhaps. Well, there are actually two problems with the above code. The first is down to a bum gizmo, the other is so bleedingly obvious you slap your forehead and ask whether you should be writing code in XCode. When you run the code you get this very helpful output from XCode:

and you’re papped back to AppDelegate with the equally helpful screech from XCode:

You then have to spend the rest of eternity working out what that lot means. It’s down to passing a nil UIView object to UIActionSheet:

The view param is set from prepareGizmoWithGizmoid but that doesn’t happen due to the glaring problem with the code. In iOS, sending a message to a nil object is meant to be benign. In this case it causes the app to blow up.

In Java you’d get a handy NullPointerException from the library that uses the view param but you’d prolly not get that far anyway as the IDE would detect gizmo being used without being initialised and flag a warning to ask if you meant it.

comments powered by Disqus