• 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: Usage of NSSortDescriptor
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Usage of NSSortDescriptor


  • Subject: Re: Usage of NSSortDescriptor
  • From: Chris Hanson <email@hidden>
  • Date: Mon, 24 Nov 2003 21:12:29 -0600

On Nov 24, 2003, at 6:29 PM, David Kocher wrote:
I would like to make use of the new NSSortDescriptor class. However I am wondering what arguments I should declare in the selector method. My sorting method never gets called.

I don't think it's a method signature issue. I suspect you're expecting this.sortByFilenames() to be called during the sort.

this.myTableView.tableColumnWithIdentifier("FILENAME").setSortDescripto rPrototype(
new NSSortDescriptor(
"FILENAME",
true,
new NSSelector("sortByFilenames", new Class[] {Object.class}))

Instead, sortByFilenames will be sent to the values actually being sorted during the sort. Here's a very simple Objective-C example:

NSSortDescriptor *desc
= [[[NSSortDescriptor alloc]
initWithKey:@"filename"
ascending:YES
selector:@selector(sortByFilenames:)] autorelease];

[myMutableArray sortArrayUsingDescriptors:[NSArray arrayWithObject:desc]];

This will go through all of the elements of myMutableArray, *get the "filename" property of each one*, and then send *that* -sortByFilenames: to determine the new ordering of the array. This has a couple of implications: First, every element in the array needs a "filename" property (either an attribute or relationship. Second, every object returned for that "filename" proprety needs to respond to -sortByFilenames:.

A corollary is that your property names -- and, generally, your table column identifiers too -- need to be in a form that's properly Key-Value Coding-compliant. To be KVC-compliant you need to follow the Objective-C & Smalltalk naming convention, i.e. lower case with internal capitalization. The reason is that Cocoa will use the key you specify to generate the name of a method to call or instance variable to access according to the conventions used by KVC.

-- Chris

--
Chris Hanson <email@hidden>
bDistributed.com, Inc.
Outsourcing Vendor Evaluation
Custom Mac OS X Development
Cocoa Developer Training
_______________________________________________
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: 
 >Usage of NSSortDescriptor (From: David Kocher <email@hidden>)

  • Prev by Date: Re: Cocoa applications as "droplets"
  • Next by Date: Re: Stupid question: Flood Fill
  • Previous by thread: Re: Usage of NSSortDescriptor
  • Next by thread: NSSize not found in XCode
  • Index(es):
    • Date
    • Thread