I have an object with two properties - type
and name
- which I want to show in its description
. The out-of-the-box description looks like this:
<SGBMessage: 0x7663bb0>
If I override description
, like so:
return [NSString stringWithFormat:@"<%@: %x type:%@ name%@>",
[self class], (int)self, self.type, self.name];
Then I can get a nice description like this:
<SGBMessage: 0x7663bb0 type:loadScreen name:mainScreen>
So far, so good. But Apple's objects have dynamic descriptions; if I look at a view's description I get this:
<UIView: 0x767bcb0; frame = (0 0; 0 0); layer = <CALayer: 0x767bd50>>
But if I set hidden to true, I get this:
<UIView: 0x767bcb0; frame = (0 0; 0 0); hidden = YES;
layer = <CALayer: 0x767bd50>>
Now, I don't believe for a second that they've got a massive set of if statements in the description
methods of all of their objects; it seems much more likely that there's some method in some category somewhere on NSObject that can be overridden to specify which properties show up in the description. Does anyone know what's really going on, and if so, is it something I can take advantage of?