views:

405

answers:

1

Hello thogether

While searching a bug in my code today I found a strange thing. When inspecting a UIView instance in the debugger the variable view of Xcode does not show the subviews member of the UIView class.

I only see this fields in the debugger (> should indicate the opening triangle):

  • >UIResponder
  • >_layer
  • >_tabInfo
  • >_gestureInfo
  • >_touchData
  • _charge
  • _tag
  • >_viewFlags

I'm missing the _subviews member and come to think of it also all the positional members (at least one of them should be there).

Does anybody know what I'm missing or doing wrong (as far as I can tell it is not a problem as a google search for this problem didn't got me any results).

I use Xcode version 3.1.3 with:

  • XcodeIDE: 1191.0
  • XcodeCore: 1192.0
  • XcodeSupport: 1186.0

on a mac with OS 10.5.7 and iPhone SDK 2.2.1 (I also tested with iPhone SDK 3.0).

I hope somebody knows anything about this. It gives me a little strange feeling that I cannot trust the debugger to show me everything I should know for debugging a problem. And it's not good if you need to mistrust you tools :(

+1  A: 

The debugger is only going to be able to show you members, not properties. Remember that the two are different in Objective C. A property is just syntactic sugar for a setter and/or a getter. So the read-only "subviews" property of UIView only guarantees that it has an implementation for this method:

- (NSArray *)subviews;

As you've noticed, Apple has implemented many of their properties using undocumented member variables that resemble their corresponding property names, but with leading underscores. This allows you to spy on the internals of some objects to see what's going on in some cases, but many properties aren't implemented in such a transparent manner. In these cases, you'll need to inject some diagnostic code into your app to access the property and output its return value using NSLog, and/or store the value in a temporary variable that you can observe in your debugger.

Don't blame the poor debugger. It's doing exactly what it's designed to do. If it helps, you can blame properties for trying to trick us into thinking they're member variables when they're really methods.

cduhn
Ok, I see now what the problem is. Thanks for helping out.
Chris