Created
August 20, 2012 12:47
-
-
Save dystonie/3403787 to your computer and use it in GitHub Desktop.
Recursive NSView navigator
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
static inline NSSet *recursiveTroughtSubviews(NSView *aView, NSSet *previousResults) { | |
NSMutableSet *tmpSet = [NSMutableSet set]; | |
//There are objects | |
if (aView && [aView subviews] > 0) { | |
//Enumerate array | |
NSArray *viewsToNavigate = [aView subviews]; | |
for (NSView *obj in viewsToNavigate) { | |
//Add selected objects | |
[tmpSet addObject:obj]; | |
if (previousResults) | |
[tmpSet addObjectsFromArray:[previousResults allObjects]]; | |
//Reiterate the function | |
[tmpSet addObjectsFromArray:[recursiveTroughtSubviews(obj, [tmpSet retain]) allObjects]]; | |
} | |
//Returns a set | |
return [[NSSet alloc] initWithSet:tmpSet]; | |
} | |
//View has no subviews | |
else | |
return nil; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment