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.
.gif)
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.
Cheers,
Volker
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.
Try F-Script.
I think that’s a great idea. It reminds me of Jeff’s debugging tool in Nimbus: https://plus.google.com/110641278680887196477/posts/8nA7GiLwvib
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: http://hayne.net/MacDev/ViewHierarchy/
This other one seems to run in the simulator: https://github.com/domesticcatsoftware/DCIntrospect. 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: http://iphonedevwiki.net/index.php/UIView#-recursiveDescription
Have a look at this library on github, it may help.
https://github.com/domesticcatsoftware/DCIntrospect
Hi Volker,
I think DCIntrospect will go some way to fulfilling your needs, or at least give you some code that traverses the view hierarchy to start with.
https://github.com/domesticcatsoftware/DCIntrospect
Pat, who wrote the tool, gave an awesome introductory presentation on it at the last Melbourne Cocoaheads meetup. The video should be up on http://www.melbournecocoaheads.com/ some time soon
– Stew
@stewgleadow
Hi,
I dont know if you are familiar with this tool, but fscript might be what you are looking for.
Check out: http://www.fscript.org/.
Check out https://github.com/domesticcatsoftware/DCIntrospect
It’s not as comfortable as Spy++ probably is and is mostly limited to the Simulator (it uses a hidden UITextView to intercept keystrokes) but it is still a big step forward.
Check out F-Script: http://www.fscript.org/
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!
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 🙂
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: http://www.sparkinspector.com/. 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!
Hey Ben,
this looks fantastic, thanks for the info!