Assuming you're using NSOutlineViewDataSource and not bindings, you could do it like this:
- (void)iterateItemsInOutlineView: (NSOutlineView*)outlineView
{
id<NSOutlineViewDataSource> dataSource = outlineView.dataSource;
NSMutableArray* stack = [NSMutableArray array];
do
{
// Pop an item off the stack
id currentItem = stack.lastObject;
if (stack.count)
[stack removeLastObject];
// Push the children onto the stack
const NSUInteger childCount = [dataSource outlineView: outlineView numberOfChildrenOfItem: currentItem];
for (NSUInteger i = 0; i < childCount; ++i)
[stack addObject: [dataSource outlineView: outlineView child: i ofItem: currentItem]];
// Visit the current item.
if (nil != currentItem)
{
// Do whatever you want to do to each item here...
}
} while (stack.count);
}
This should achieve a full traversal of all the objects vended by your NSOutlineViewDataSource.
FYI: If you're using cocoa bindings, this won't work as is. If that's the case, though, you could use a similar approach (i.e. surrogate-stack traversal) against the NSTreeController (or whatever else) you're binding to.
HTH