Skip to content

Instantly share code, notes, and snippets.

@gavingmiller
Created June 11, 2012 14:43
Show Gist options
  • Save gavingmiller/2910402 to your computer and use it in GitHub Desktop.
Save gavingmiller/2910402 to your computer and use it in GitHub Desktop.
Objective-C Dump Views
static void dumpViews(UIView* view, NSString *text, 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];
dumpViews(subView, msg, newIndent);
[msg release];
[newIndent release];
}
}
def dump_views(view, text = "", indent = "")
klass = view.class
klassDescription = klass.description
while klass.superclass
klass = klass.superclass
klassDescription = klassDescription + ":#{klass.description}"
end
if text.compare("") == NSOrderedSame
puts "#{klassDescription} #{NSStringFromCGRect(view.frame)}"
else
puts "#{text} #{klassDescription} #{NSStringFromCGRect(view.frame)}"
end
view.subviews.each_index do |i|
subview = view.subviews.objectAtIndex(i)
newIndent = " #{indent}"
message = "#{newIndent}#{i}"
dump_views(subview, message, newIndent)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment