Skip to content

Instantly share code, notes, and snippets.

@rkachowski
Last active August 29, 2015 13:56
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 rkachowski/8801621 to your computer and use it in GitHub Desktop.
Save rkachowski/8801621 to your computer and use it in GitHub Desktop.
Do the same as UIKit#recursiveDescription, but for CCNode instead of UIView
#import <Foundation/Foundation.h>
#import "CCNode.h"
@interface CCNode (RecursiveDescription)
- (NSString*)recursiveDescription;
@end
@implementation CCNode (RecursiveDescription)
- (NSString*)recursiveDescription
{
return [self recursivelyListChildren:0];
}
- (NSString*)recursivelyListChildren:(NSUInteger)depth
{
NSString * padding = @"";
for(int i =0; i < depth;i++)
{
padding = [NSString stringWithFormat:@"%@ | ", padding];
}
NSString *description = [NSString stringWithFormat:@"%@%@", padding, self.description];
NSMutableArray *children = [@[description] mutableCopy];
for(CCNode * node in _children)
{
[children addObject:[node recursivelyListChildren:depth + 1]];
}
return [children componentsJoinedByString:@"\n"];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment