Jakub Lédl Jakub Lédl - 8 months ago 64
Objective-C Question

How to use NSTableView's selectedRowIndexes?

I'm just learning some basic programming in Objective C and Cocoa. I'm trying to get some data from NSTableView. Based on what I read in one tutorial, I wrote this:

NSArray * items = [[itemsTableView selectedRowEnumerator] allObjects];

But then I learned that
was deprecated already in 10.3 Panther and that I should use

The problem is, I didn't find how to actually use the returned
to achieve the same result as with code written above.

So, If anyone could give me a tip, I would be very grateful. Thanks.


You can loop through the indexes of an NSIndexSet like this:

- (void) goThroughIndexSet:(NSIndexSet *) anIndexSet
    NSUInteger idx = [anIndexSet firstIndex];

    while (idx != NSNotFound)
        // do work with "idx"
        NSLog (@"The current index is %u", idx);

        // get the next index in the set
        idx = [anIndexSet indexGreaterThanIndex:idx];

    // all done