• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSIndexSet question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSIndexSet question


  • Subject: Re: NSIndexSet question
  • From: "Mark A. Stratman" <email@hidden>
  • Date: Fri, 11 Jun 2004 21:22:29 -0500

I was recently facing a similar problem, and found no "Good" solution. I ended up with something like:

unsigned int bufSize = [set count];
unsigned int *buf = (unsigned int*) malloc(sizeof(unsigned int) * bufSize);
NSRange range = NSMakeRange([set firstIndex], ([set lastIndex]-[set firstIndex]) + 1);
[set getIndexes:buf maxCount:bufSize inIndexRange:&range];
for (i = 0; i != bufSize; i++) {
// do stuff with buf[i], you'd probably have something like:
// [mutableTmpArray addObject:[yourArray objectAtIndex:buf[i]]];
}
free(buf);

hth,
- Mark

On Jun 11, 2004, at 7:04 PM, Glenn Zelniker wrote:

Is it possible to select the elements of an NSArray in a quick way based on the elements of an NSIndexSet? By "quick" I mean in a way other than traversing the index set with -firstIndex, -lastIndex, and -indexLessThan methods. For example, suppose I have a tableView with multiple selection enabled and I get the row indices using NSTableView's -selectedRowIndexes method. Now, I want to use these indices to build a new NSArray based on the objects in an arbitrary array at the indices specified in the indexSet,

There doesn't seem to be an -(NSArray *)objectsAtIndexSet:(NSIndexSet *)indices method for arrays. Am I missing something?

Glenn Zelniker
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >NSIndexSet question (From: Glenn Zelniker <email@hidden>)

  • Prev by Date: Re: 30 day trial howto?
  • Next by Date: Re: Retain cycle problem with bindings & NSWindowController
  • Previous by thread: NSIndexSet question
  • Next by thread: Re: Smooth Animation
  • Index(es):
    • Date
    • Thread