Last active
December 15, 2015 23:29
-
-
Save mafua/5340713 to your computer and use it in GitHub Desktop.
Category to help searching through SPDisplayObjectContainer objects recursively, given the object's name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SPDisplayObjectContainer+Recursive.h | |
// | |
// Created by Henrique Cabral on 4/3/13. | |
// | |
// | |
#import "SPDisplayObjectContainer.h" | |
@interface SPDisplayObjectContainer (Recursive) | |
- (SPDisplayObject*) childByNameRecursive:(NSString *)name container:(SPDisplayObject*)object; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SPDisplayObjectContainer+Recursive.m | |
// | |
// Created by Henrique Cabral on 4/3/13. | |
// | |
// | |
#import "SPDisplayObjectContainer+Recursive.h" | |
@implementation SPDisplayObjectContainer (Recursive) | |
- (SPDisplayObject*) childByNameRecursive:(NSString *)name container:(SPDisplayObject*)object | |
{ | |
SPDisplayObject *current = nil; | |
if ([object.name isEqualToString:name]) | |
{ | |
current = object; | |
} | |
if ([object isKindOfClass:[SPDisplayObjectContainer class]] && !current) | |
{ | |
for (SPDisplayObject *child in (SPDisplayObjectContainer*)object) | |
{ | |
current = [self childByNameRecursive:name container:child]; | |
if (current) | |
break; | |
} | |
} | |
return current; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment