Skip to content

Instantly share code, notes, and snippets.

@mattsgarrison
Forked from gavingmiller/dump.m
Created June 12, 2012 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattsgarrison/2914632 to your computer and use it in GitHub Desktop.
Save mattsgarrison/2914632 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