Debugging Cocoa

Hey iDevBlogADay,

we recently had an issue in Cocoa, where for some reason we had two view controllers active at the same time (with two OpenGLES views active), leading to a bunch of issues. I then realized that there seem to be no good Cocoa debugging tools. From my Win32 days, I remember that little tool Spy++, which could inspect the window hierarchy. That was a great to help ensure everything is sane. I think with a tool like this many bugs in our Cocoa apps could’ve been avoided or more easily spotted.

A tool like Spy++ is missing for iOS

A tool like Spy++ is missing for iOS

Now, it doesn’t seem that there is something comparable for Cocoa. As a matter of fact, it doesn’t seem like there is _anything_ at all even in the debugging tools in XCode to even inspect the view hierarchy, and see what resources are allocated and used right now.

So I looked into some of the APIs and I noticed that it’s actually quite easy to fetch most of this stuff. UIApplication gives access to all windows, which in turn gives access to all views and subviews. Hence, I started thinking about implementing a little Mac tool that connects to a little server running in your debug iOS application, which could fetch the hierarchy and send it to the desktop for inspection.

But before I start writing a tool like this (which I’d open source), I wanted to ask the iDevBlogADay community if anyone has seen a something similar to this out in the wilds of the internet.



12 thoughts on “Debugging Cocoa

  1. A proper tool would be great, but in the meantime, check out UIView’s recursiveDescription method. Take a look at the iOS Debugging Magic tech note as well.

  2. Well, I can find 2 that may help. This one is for Mac, but you probably can download the code and make the pertinent changes to run it on iOS:

    This other one seems to run in the simulator: It uses the UIView private method recursiveDescription to print the hierarchy to the console, plus some other info on the screen.

    BTW, I have never needed more than that private method myself:

  3. Check out F-Script:

    You can either embed it in debug builds of your application, or inject it (into any cocoa app) at runtime (look for “F-Script Anywhere” for that). It gives you a graphical object browser and a command-line interface with a lightweight language which let you introspect and even modify the state of objects at runtime. Both of which are extremely useful for tracking down UI bugs!

  4. Wow, those are great suggestions! There is def. more than enough tools to debug those kinds of problems, I’m looking forward to having a chance to try them 🙂

  5. I’m a little late to the party, but I’ve been developing a tool like Spy++ for our team to use in-house for the last year. I think you’ll like it—I think it’s a lot closer to Spy++ than DCIntrospect or FScript. It’s aiming to be Instruments for UIViews, and we just put the finishing touches on a public version: Try it out and let me know what you think—I’d be happy to send you a free copy if you want to do a post about it!

Leave a Reply

Your email address will not be published. Required fields are marked *