views:

89

answers:

1

I'm getting the select items from a table view with:

NSIndexSet *selectedItems = [aTableView selectedRowIndexes];

what's the best way to get the indexes in a NSArray object?

+4  A: 

Enumerate the set, make NSNumbers out of the indexes, add the NSNumbers to an array.

That's how you'd do it. I'm not sure I see the point in transforming a set of indexes into a less efficient representation, though.

To enumerate a set, you have two options. If you're targeting OS X 10.6 or iOS 4, you can use enumerateIndexesUsingBlock:. If you're targeting earlier versions, you'll have to get the firstIndex and then keep asking for indexGreaterThanIndex: on the previous result until you get NSNotFound.

Chuck
you're right it's just that i don't know how to get the indexes from the NSIndexSet with a while loop or a foreach loop....
Mr_Nizzle
It's in the docs: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Collections/Articles/index.html%23//apple_ref/doc/uid/TP40010165-SW4
Wevah
@Wevah perfect man !!!
Mr_Nizzle
@Chuck Cool man Thanks !
Mr_Nizzle