Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSSortDescriptor

Inherits from
Implements
Package
com.apple.cocoa.foundation
Availability
Available in Mac OS X v10.3 and later.
Companion guide

Overview

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.

Tasks

Constructors

Getting Information About a Sort Descriptor

Using Sort Descriptors

Constructors

NSSortDescriptor

Creates and returns an empty NSSortDescriptor.

public NSSortDescriptor()

Availability

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)

Availability

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)

Availability

Instance Methods

ascending

Returns a Boolean value that indicates whether the receiver will sort items in ascending order.

public boolean ascending()

Availability

compareObjects

public int compareObjects(Object object1, Object object2)

Discussion

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.

Availability

key

Returns the receiver’s property key.

public String key()

Discussion

This key specifies the property that is compared during sorting.

Availability

reversedSortDescriptor

Returns a copy of the receiver with the sort order reversed.

public Object reversedSortDescriptor()

Availability

selector

Returns the selector the receiver will use when comparing objects.

public NSSelector selector()

Availability


Next Page > Hide TOC


© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.