Mac Developer Library

Developer

AppKit Framework Reference NSArrayController Class Reference

Options
Deployment Target:

On This Page
Language:

NSArrayController

NSArrayController is a bindings compatible class that manages a collection of objects. Typically the collection is an array, however, if the controller manages a relationship of a managed object (see NSManagedObject) the collection may be a set. NSArrayController provides selection management and sorting capabilities.

Conforms To


Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.3 and later.
  • An array of NSSortDescriptor objects, used by the receiver to arrange its content

    Declaration

    Swift

    var sortDescriptors: [AnyObject]!

    Objective-C

    @property(copy) NSArray *sortDescriptors

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns a given array, appropriately sorted and filtered.

    Declaration

    Swift

    func arrangeObjects(_ objects: [AnyObject]) -> [AnyObject]

    Objective-C

    - (NSArray *)arrangeObjects:(NSArray *)objects

    Return Value

    An array containing objects filtered using the receiver's filter predicate (see filterPredicate) and sorted according to the receiver’s sortDescriptors.

    Discussion

    Subclasses should override this method to use a different sort mechanism, provide custom object arrangement, or (typically only prior to OS X version 10.4, which provides a filter predicate) filter the objects.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • An array containing the receiver’s content objects arranged using arrangeObjects:. (read-only)

    Declaration

    Swift

    var arrangedObjects: AnyObject { get }

    Objective-C

    @property(readonly, strong) id arrangedObjects

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Triggers filtering of the receiver’s content.

    Declaration

    Swift

    func rearrangeObjects()

    Objective-C

    - (void)rearrangeObjects

    Discussion

    This method invokes arrangeObjects:.

    When you detect that filtering criteria change (such as when listening to the text sent by an NSSearchField instance), invoke this method on self.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Creates and adds a new object to the receiver’s content and arranged objects.

    Declaration

    Swift

    func add(_ sender: AnyObject?)

    Objective-C

    - (void)add:(id)sender

    Parameters

    sender

    Typically the object that invoked this method.

    Special Considerations

    Beginning with OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism (see Error Responders and Error Recovery in Error Handling Programming Guide) can provide feedback as a sheet.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • A Boolean value that indicates whether the receiver requires that the content array attempt to maintain a selection

    Declaration

    Swift

    var avoidsEmptySelection: Bool

    Objective-C

    @property BOOL avoidsEmptySelection

    Discussion

    The default is YEStrue. This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • A Boolean value that indicates whether the receiver will attempt to preserve the current selection when the content changes

    Declaration

    Swift

    var preservesSelection: Bool

    Objective-C

    @property BOOL preservesSelection

    Discussion

    The default is YEStrue. This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • A Boolean value that indicates whether the receiver always returns the multiple values marker when multiple objects are selected

    Declaration

    Swift

    var alwaysUsesMultipleValuesMarker: Bool

    Objective-C

    @property BOOL alwaysUsesMultipleValuesMarker

    Discussion

    The default is NOfalse. Setting to YEStrue can increase performance if your application doesn’t allow editing multiple values. This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • The index of the first object in the receiver’s selection (read-only)

    Declaration

    Swift

    var selectionIndex: Int { get }

    Objective-C

    @property(readonly) NSUInteger selectionIndex

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the receiver’s selection to the given index, and returns a Boolean value that indicates whether the selection was changed.

    Declaration

    Swift

    func setSelectionIndex(_ index: Int) -> Bool

    Objective-C

    - (BOOL)setSelectionIndex:(NSUInteger)index

    Parameters

    index

    The index for the selection.

    Return Value

    YEStrue if the selection was changed, otherwise NOfalse.

    Discussion

    Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets whether the receiver will automatically select objects as they are inserted.

    Declaration

    Swift

    var selectsInsertedObjects: Bool

    Objective-C

    @property BOOL selectsInsertedObjects

    Parameters

    flag

    If YEStrue then items will be selected upon insertion.

    Discussion

    The default is YEStrue.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • A Boolean value that indicates whether the receiver automatically selects inserted objects

    Declaration

    Swift

    var selectsInsertedObjects: Bool

    Objective-C

    @property BOOL selectsInsertedObjects

    Discussion

    The default is YEStrue. This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the receiver’s selection indexes and returns a Boolean value that indicates whether the selection changed.

    Declaration

    Swift

    func setSelectionIndexes(_ indexes: NSIndexSet!) -> Bool

    Objective-C

    - (BOOL)setSelectionIndexes:(NSIndexSet *)indexes

    Parameters

    indexes

    The set of selection indexes for the receiver.

    Return Value

    YEStrue if the selection was changed, otherwise NOfalse.

    Discussion

    Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.

    To select all the receiver’s objects, indexes should be an index set with indexes [0...count -1]. To deselect all indexes, pass an empty index set.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • An index set containing the indexes of the receiver’s currently selected objects in the content array (read-only)

    Declaration

    Swift

    @NSCopying var selectionIndexes: NSIndexSet { get }

    Objective-C

    @property(readonly, copy) NSIndexSet *selectionIndexes

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Adds the objects at the specified indexes in the receiver’s content array to the current selection, returning YEStrue if the selection was changed.

    Declaration

    Swift

    func addSelectionIndexes(_ indexes: NSIndexSet) -> Bool

    Objective-C

    - (BOOL)addSelectionIndexes:(NSIndexSet *)indexes

    Discussion

    Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Removes the object as the specified indexes from the receiver’s current selection, returning YEStrue if the selection was changed.

    Declaration

    Swift

    func removeSelectionIndexes(_ indexes: NSIndexSet) -> Bool

    Objective-C

    - (BOOL)removeSelectionIndexes:(NSIndexSet *)indexes

    Discussion

    Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets objects as the receiver’s current selection, returning YEStrue if the selection was changed.

    Declaration

    Swift

    func setSelectedObjects(_ objects: [AnyObject]) -> Bool

    Objective-C

    - (BOOL)setSelectedObjects:(NSArray *)objects

    Discussion

    Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • An array containing the receiver’s selected objects (read-only)

    Declaration

    Swift

    var selectedObjects: [AnyObject]! { get }

    Objective-C

    @property(readonly, copy) NSArray *selectedObjects

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Adds objects from the receiver’s content array to the current selection, returning YEStrue if the selection was changed.

    Declaration

    Swift

    func addSelectedObjects(_ objects: [AnyObject]) -> Bool

    Objective-C

    - (BOOL)addSelectedObjects:(NSArray *)objects

    Discussion

    Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Removes objects from the receiver’s current selection, returning YEStrue if the selection was changed.

    Declaration

    Swift

    func removeSelectedObjects(_ objects: [AnyObject]) -> Bool

    Objective-C

    - (BOOL)removeSelectedObjects:(NSArray *)objects

    Discussion

    Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Selects the next object, relative to the current selection, in the receiver’s arranged content.

    Declaration

    Swift

    func selectNext(_ sender: AnyObject?)

    Objective-C

    - (void)selectNext:(id)sender

    Discussion

    The sender is typically the object that invoked this method.

    Special Considerations

    Beginning with OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism (see Error Responders and Error Recovery in Error Handling Programming Guide) can provide feedback as a sheet.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • A Boolean value indicating whether the next object, relative to the current selection, in the receiver’s content array can be selected (read-only)

    Declaration

    Swift

    var canSelectNext: Bool { get }

    Objective-C

    @property(readonly) BOOL canSelectNext

    Discussion

    This property can be used by a binding to enable user interface items. This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Selects the previous object, relative to the current selection, in the receiver’s arranged content.

    Declaration

    Swift

    func selectPrevious(_ sender: AnyObject?)

    Objective-C

    - (void)selectPrevious:(id)sender

    Discussion

    The sender is typically the object that invoked this method.

    Special Considerations

    Beginning with OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism (see Error Responders and Error Recovery in Error Handling Programming Guide) can provide feedback as a sheet.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • A Boolean value indicating whether the previous object, relative to the current selection, in the receiver’s content array can be selected (read-only)

    Declaration

    Swift

    var canSelectPrevious: Bool { get }

    Objective-C

    @property(readonly) BOOL canSelectPrevious

    Discussion

    This property can be used by a binding to enable user interface items. This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • canInsert canInsert Property

    Returns a Boolean value that indicates whether an object can be inserted into the receiver’s content collection. (read-only)

    Declaration

    Swift

    var canInsert: Bool { get }

    Objective-C

    @property(readonly) BOOL canInsert

    Discussion

    The result of this method can be used by a binding to enable user interface items.

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    See Also

    – insert:

  • Creates a new object and inserts it into the receiver’s content array.

    Declaration

    Swift

    func insert(_ sender: AnyObject?)

    Objective-C

    - (void)insert:(id)sender

    Parameters

    sender

    Typically the object that invoked this method.

    Discussion

    If an entity name is specified (see entityName), this method creates an instance of the of the class specified by the entity, otherwise this method creates an instance of the class specified by objectClass.

    Special Considerations

    Beginning with OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism (see Error Responders and Error Recovery in Error Handling Programming Guide) can provide feedback as a sheet.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    See Also

    canInsert

  • A Boolean value that indicates whether the receiver automatically clears an existing filter predicate when new items are inserted or added to the content

    Declaration

    Swift

    var clearsFilterPredicateOnInsertion: Bool

    Objective-C

    @property BOOL clearsFilterPredicateOnInsertion

    Discussion

    The default is YEStrue. This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • A predicate used by the receiver to filter the array controller contents

    Declaration

    Swift

    var filterPredicate: NSPredicate?

    Objective-C

    @property(strong) NSPredicate *filterPredicate

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • A Boolean that indicates if the receiver automatically rearranges its content to correspond to the current sort descriptors and filter predicates

    Declaration

    Swift

    var automaticallyRearrangesObjects: Bool

    Objective-C

    @property BOOL automaticallyRearrangesObjects

    Discussion

    The default is NOfalse.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • An array of key paths that trigger automatic content sorting or filtering (read-only)

    Declaration

    Swift

    var automaticRearrangementKeyPaths: [AnyObject]? { get }

    Objective-C

    @property(readonly, copy) NSArray *automaticRearrangementKeyPaths

    Discussion

    Subclasses can override this property to customize the default behavior of the sort descriptors and filtering predicates, for example, if additional arrangement criteria are used in a custom implementation of arrangedObjects.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Invoked when any criteria for arranging objects change.

    Declaration

    Swift

    func didChangeArrangementCriteria()

    Objective-C

    - (void)didChangeArrangementCriteria

    Discussion

    This method is invoked by the controller itself when any criteria for arranging objects change (sort descriptors or filter predicates) to reset the key paths for automatic rearranging.

    Special Considerations

    If you implement a subclass of NSArrayController and override rearrangeObjects to use additional arrangement criteria, you should invoke this method if those criteria change.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.