Skip to content

Instantly share code, notes, and snippets.

@PiotrCzapla
Created April 5, 2012 11:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PiotrCzapla/2310280 to your computer and use it in GitHub Desktop.
Save PiotrCzapla/2310280 to your computer and use it in GitHub Desktop.
Dump view hierarchy to NSLog
#import <Foundation/Foundation.h>
@interface DebugUtils : NSObject
/**
* Dump view hierarchy to NSLog
*/
+ (void) dumpViews:(UIView*)view;
@end
// code based on http://stackoverflow.com/questions/289441/uinavigationcontroller-title-can-be-some-image/428434#428434
#import "DebugUtils.h"
@implementation DebugUtils
+ (void) dumpViews:(UIView*) view label:(NSString *) text indent:(NSString*) indent{
Class cl = [view class];
NSString *classDescription = [cl description];
while ([cl superclass]) {
cl = [cl superclass];
classDescription = [classDescription stringByAppendingFormat:@":%@", [cl description]];
}
if ([text compare:@""] == NSOrderedSame) {
NSLog(@"%@ %@", classDescription, NSStringFromCGRect(view.frame));
} else {
NSLog(@"%@ %@ %@", text, classDescription, NSStringFromCGRect(view.frame));
}
for (NSUInteger i = 0; i < [view.subviews count]; i++)
{
UIView *subView = [view.subviews objectAtIndex:i];
NSString *newIndent = [[NSString alloc] initWithFormat:@" %@", indent];
NSString *msg = [[NSString alloc] initWithFormat:@"%@%d:", newIndent, i];
[DebugUtils dumpViews:subView label:msg indent:newIndent];
}
}
+ (void) dumpViews:(UIView*) view {
[DebugUtils dumpViews:view label:@"" indent:@""];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment