Skip to content

Instantly share code, notes, and snippets.

@oropon
Created March 14, 2013 08:39
Show Gist options
  • Save oropon/5159805 to your computer and use it in GitHub Desktop.
Save oropon/5159805 to your computer and use it in GitHub Desktop.
My recursive description (iOS/OSX)(ARC/ManualMemoryManagement)
#if TARGET_OS_IPHONE
@interface UIView (RecursiveDescription)
#else
@interface NSView (RecursiveDescription)
#endif
#ifdef DEBUG
- (NSString*)_recursiveDescription;
#endif
@end
#if TARGET_OS_IPHONE
@implementation UIView (RecursiveDescription)
#else
@implementation NSView (RecursiveDescription)
#endif
- (NSString*)_recursiveDescription
{
return _recursiveDescription(self, 0);
}
NSString* _recursiveDescription(id view, NSUInteger depth)
{
NSMutableString* subviewsDescription;
subviewsDescription = [NSMutableString string];
for (id v in [view subviews]) {
[subviewsDescription appendString:_recursiveDescription(v, depth+1)];
}
NSMutableString* layout;
layout = [NSMutableString string];
for (int i = 0; i < depth; i++) {
[layout appendString:@" | "];
}
return [NSString stringWithFormat:@"%@%@\n%@", layout, [view description], subviewsDescription];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment