Enumerating the iPhone’s View Hierarchy

So iOS 4.0 broke the "numeric keypad with decimal point"-hack. To verify that the UIKeyboardView was removed somehow from the app's view hierarchy I wrote a small function. Yeah, looks like there's no keyboard view in the hierarchy :(

Nevertheless I found the method handy. So here it is:

void enumerateSubviews (id viewlol)
{
  static int enum_level = 0;

  enum_level ++;
  NSMutableString *tabstring = [NSMutableString stringWithCapacity: 8];
  for (int i = 0; i < enum_level; i++)
    [tabstring appendString:@"---"];

  NSLog(@"%@%@",tabstring, viewlol);
  NSLog(@"%@{",tabstring);

  for (int i = 0; i < [[viewlol subviews] count]; i++)
  {
    id temp = [[viewlol subviews] objectAtIndex: i];

    if ([[temp subviews] count] > 0)
      enumerateSubviews (temp);
    else
      NSLog(@"%@%@",tabstring,temp);
  }
  NSLog(@"%@}",tabstring);
  enum_level --;
}

Just pass a UIWindow/UIView to it and you will see what is attached to that view. It's recursive and has no depth break - so if you happen to kill the stack build an abort condition in :)