Skip to content

Instantly share code, notes, and snippets.

@dystonie
Created August 20, 2012 12:47
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 dystonie/3403787 to your computer and use it in GitHub Desktop.
Save dystonie/3403787 to your computer and use it in GitHub Desktop.
Recursive NSView navigator
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