Return to Snippet

Revision: 16668
at August 11, 2009 22:04 by phifty


Initial Code
#define objectString(anObject) [[anObject description] UTF8String]

#import <Foundation/Foundation.h>
@interface Util : NSObject {}
+ (void)explode:(id)viewObj level:(int)level;
@end

@implementation Util
+ (void)explode:(id)viewObj level:(int)level
{
	//	indent to show the current level
	for (int i = 0; i < level; i++) {
		printf("-", level);
	}
	
	//	show the class and superclass for the current object
	printf("%s : ", objectString([viewObj class]));
	id obj = [viewObj superclass];
	
	while (NULL != obj) {
		printf("%s : ", objectString([obj class]));
		obj = [obj superclass];
	}
	
	printf("\n");
	
	//	recurse for all subviews
	for (UIView *sub in [viewObj subviews]) {
		[Util explode:sub level:(level + 1)];
	}
}
@end

Initial URL


Initial Description
This is adapted from Erica Sadun's explode code in her book "iPhone Developer's Cookbook".
It takes any UIView-based element and exposes all of the subviews and their subviews, etc.
Its a good way to dig into UIKit elements as well as debug your own UIView-based code.
In code, always set level to zero.

Initial Title
UIView and Subviews Exploded

Initial Tags


Initial Language
Objective C