Important: The information in this document is obsolete and should not be used for new development.
Inherits from | |
Implements | |
Package | com.apple.cocoa.foundation |
Availability | Available in Mac OS X v10.3 and later. |
Companion guide |
NSSortDescriptor describes how an array of objects should be sorted. Objects of this class do not actually sort the array, the sort methods are defined as a category on NSArray and NSMutableArray. Instances of NSSortDescriptor are immutable.
You construct objects of this class by specifying the property key to be compared, the order of the sort (ascending or descending), and a selector that is used to perform the comparison. If null, the selector parameter defaults to the selector compare
. The three-argument constructor allows you to specify other comparison selectors such as caseInsensitiveCompare
and localizedCompare
. Sorting throws an exception if the objects to be sorted do not respond to the sort descriptor’s comparison selector.
Creates and returns an empty NSSortDescriptor.
public NSSortDescriptor
()
Creates and returns an NSSortDescriptor with the property key specified by key, sort order specified by ascending, and the default selector compare
.
public NSSortDescriptor
(String key, boolean ascending)
Creates and returns an NSSortDescriptor with the property key specified by key, sort order specified by ascending, and the selector specified by selector.
public NSSortDescriptor
(String key, boolean ascending, NSSelector selector)
Returns a Boolean value that indicates whether the receiver will sort items in ascending order.
public boolean ascending
()
public int compareObjects
(Object object1, Object object2)
Compares object1 with object2, using the selector specified by the receiver. Returns OrderedAscending
if object1 is less than object2, OrderedDescending
if object1 is greater than object2, or OrderedSame
if object1 is equal to object2.
Returns the receiver’s property key.
public String key
()
This key specifies the property that is compared during sorting.
Returns a copy of the receiver with the sort order reversed.
public Object reversedSortDescriptor
()
Returns the selector the receiver will use when comparing objects.
public NSSelector selector
()
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)