When I was preparing my talk about remote debugging toolset PonyDebugger at NSLondon I had a pre-presentation in front of my lovely co-workers. I was talking a lot about debugging and how to be efficient when doing this. After finished the talk I was asked many questions but this stood out…
Luka, why don’t you write code without bugs?
Good question, but that’s just how it is. We are all humans after all and we make mistakes sometimes. Or maybe the third party libraries we use are not polished enough and specific methods do not function properly so you need to debug.
Just a random model
So with an abundance of models in your project imagine that you have a model for
You are fiddling around, debugging and inspecting the values that are held inside a newly created object.
Let’s debug, yay!
Let’s do things like this and waste our time:
2014-03-25 21:53:28.488 Debug[6752:60b] <LBPerson: 0x8c6a110>
2014-03-25 21:55:06.740 Debug[6794:60b] Luka
This is not very useful. And it takes too much time to write these annoying
The right way
If you take a look and dive into
NSObject header file you will see these two methods:
In the iOS Developer Library, more specifically in Mac OS X Debugging Magic you can see the definition for
All Cocoa objects (everything derived from NSObject) support a description method that returns an NSString describing the object.
But in most cases the default description is not enough. You can still get some information out but it can be done better.
You can take advantage of
lldb debugger and use
po will basically call the
debugDescription method which by default invokes
description method of the specified object.
You can decouple these by implementing
debugDescription on your own.