NSArrayController Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in OS X v10.3 and later. |
| Declared in | NSArrayController.h |
| Companion guides | |
Overview
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.
Tasks
Managing Sort Descriptors
Arranging Objects
Managing Content
Selection Attributes
-
– setAvoidsEmptySelection: -
– avoidsEmptySelection -
– setClearsFilterPredicateOnInsertion: -
– preservesSelection -
– setPreservesSelection: -
– alwaysUsesMultipleValuesMarker -
– setAlwaysUsesMultipleValuesMarker:
Managing Selections
-
– selectionIndex -
– setSelectionIndex: -
– setSelectsInsertedObjects: -
– selectsInsertedObjects -
– setSelectionIndexes: -
– selectionIndexes -
– addSelectionIndexes: -
– removeSelectionIndexes: -
– setSelectedObjects: -
– selectedObjects -
– addSelectedObjects: -
– removeSelectedObjects: -
– selectNext: -
– canSelectNext -
– selectPrevious: -
– canSelectPrevious
Inserting
Adding and Removing Objects
-
– addObject: -
– addObjects: -
– insertObject:atArrangedObjectIndex: -
– insertObjects:atArrangedObjectIndexes: -
– removeObjectAtArrangedObjectIndex: -
– removeObjectsAtArrangedObjectIndexes: -
– remove: -
– removeObject: -
– removeObjects:
Filtering Content
Automatic Content Rearranging
Instance Methods
add:
Creates and adds a new object to the receiver’s content and arranged objects.
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) can provide feedback as a sheet.
Availability
- Available in OS X v10.4 and later.
Declared In
NSArrayController.haddObject:
Adds object to the receiver’s content collection and the arranged objects array.
Availability
- Available in OS X v10.3 and later.
Declared In
NSArrayController.haddObjects:
Adds objects to the receiver’s content collection.
Discussion
If selectsInsertedObjects returns YES (the default), the added objects are selected in the array controller.
It is important to note that inserting many objects with selectsInsertedObjects on can cause a significant performance penalty. In this case it is more efficient to use the setContent: method to set the array, or to set selectsInsertedObjects to NO before adding the objects with addObjects:.
Availability
- Available in OS X v10.3 and later.
Declared In
NSArrayController.haddSelectedObjects:
Adds objects from the receiver’s content array to the current selection, returning YES if the selection was changed.
Discussion
Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.
Availability
- Available in OS X v10.3 and later.
Declared In
NSArrayController.haddSelectionIndexes:
Adds the objects at the specified indexes in the receiver’s content array to the current selection, returning YES if the selection was changed.
Discussion
Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.halwaysUsesMultipleValuesMarker
Returns a Boolean value that indicates whether the receiver always returns the multiple values marker when multiple objects are selected.
Return Value
YES if the receiver always returns the multiple values marker when multiple objects are selected—even if the selected items have the same value, otherwise NO.
Discussion
The default is NO.
This property is observable using key-value observing.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSArrayController.harrangedObjects
Returns an array containing the receiver’s content objects arranged using arrangeObjects:.
Return Value
An array containing the receiver’s content objects arranged using arrangeObjects:.
Discussion
This property is observable using key-value observing.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.harrangeObjects:
Returns a given array, appropriately sorted and filtered.
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.
Availability
- Available in OS X v10.3 and later.
Declared In
NSArrayController.hautomaticallyPreparesContent
Returns a Boolean value that indicates whether the receiver automatically prepares its content when it is loaded from a nib.
Return Value
YES if the receiver automatically prepares its content when loaded from a nib, otherwise NO.
Discussion
See setAutomaticallyPreparesContent: for a full explanation of "automatically prepares content."
The default is YES.
automaticallyRearrangesObjects
Returns a Boolean that indicates if the receiver automatically rearranges its content to correspond to the current sort descriptors and filter predicates.
Return Value
YES if the receiver automatically rearranges objects upon changes to the content, NO if the content does not automatically rearrange.
Availability
- Available in OS X v10.5 and later.
Declared In
NSArrayController.hautomaticRearrangementKeyPaths
Returns an array of key paths that trigger automatic content sorting or filtering.
Return Value
An array of key paths that trigger automatic content sorting or filtering.
Discussion
Subclasses can override this method 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 rearrangeObjects.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSArrayController.havoidsEmptySelection
Returns a Boolean value that indicates whether if the receiver requires that the content array attempt to maintain a selection.
Return Value
YES if the receiver requires that the content array attempt to maintain a selection at all times, otherwise NO.
Discussion
The default is YES.
This property is observable using key-value observing.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hcanInsert
Returns a Boolean value that indicates whether an object can be inserted into the receiver’s content collection.
Return Value
YES if an object can be inserted into the receiver’s content collection, otherwise NO.
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.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hcanSelectNext
Returns YES if the next object, relative to the current selection, in the receiver’s content array can be selected.
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.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hcanSelectPrevious
Returns YES if the previous object, relative to the current selection, in the receiver’s content array can be selected.
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.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hclearsFilterPredicateOnInsertion
Returns a Boolean value that indicates whether the receiver automatically clears an existing filter predicate when new items are inserted or added to the content.
Return Value
YES if the receiver automatically clears an existing filter predicate when new items are inserted or added to the content, otherwise NO.
Discussion
The default is YES.
This property is observable using key-value observing.
Availability
- Available in OS X v10.4 and later.
Declared In
NSArrayController.hdidChangeArrangementCriteria
Invoked when any criteria for arranging objects change.
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.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSArrayController.hfilterPredicate
Returns the predicate used by the receiver to filter the array controller contents.
Return Value
The predicate used by the receiver to filter the array controller contents. Returns nil if no filter predicate is set.
Discussion
This property is observable using key-value observing.
Availability
- Available in OS X v10.4 and later.
Declared In
NSArrayController.hinsert:
Creates a new object and inserts it into the receiver’s content array.
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) can provide feedback as a sheet.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hinsertObject:atArrangedObjectIndex:
Inserts object into the receiver’s arranged objects array at the location specified by index, and adds it to the receiver’s content collection.
Discussion
Subclasses can override this method to provide customized arranged objects support.
Availability
- Available in OS X v10.3 and later.
Declared In
NSArrayController.hinsertObjects:atArrangedObjectIndexes:
Inserts objects into the receiver’s arranged objects array at the locations specified in indexes, and adds it to the receiver’s content collection.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hpreservesSelection
Returns a Boolean value that indicates whether the receiver will attempt to preserve the current selection when the content changes.
Return Value
YES if the receiver attempts to preserve the current selection when the content changes, otherwise NO.
Discussion
The default is YES.
This property is observable using key-value observing.
Availability
- Available in OS X v10.3 and later.
Declared In
NSArrayController.hrearrangeObjects
Triggers filtering of the receiver’s content.
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.
Availability
- Available in OS X v10.3 and later.
Declared In
NSArrayController.hremove:
Removes the receiver’s selected objects from the content collection.
Parameters
- sender
Typically the object that invoked this method.
Discussion
See removeObject: for a discussion of the semantics of removing objects when using Core Data.
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) can provide feedback as a sheet.
Availability
- Available in OS X v10.4 and later.
Declared In
NSArrayController.hremoveObject:
Removes object from the receiver’s content collection.
Special Considerations
If you are using Core Data, the exact semantics of this method differ depending on the settings for the array controller. If the receiver’s content is fetched automatically, removed objects are marked for deletion by the managed object context (and hence removal from the object graph). If, however, the receiver’s contentSet is bound to a relationship, removeObject: by default only removes the object from the relationship (not from the object graph). You can, though, set the “Deletes Object on Remove” option for the contentSet binding, in which case objects are marked for deletion as well as being removed from the relationship.
Availability
- Available in OS X v10.3 and later.
Declared In
NSArrayController.hremoveObjectAtArrangedObjectIndex:
Removes the object at the specified index in the receiver’s arranged objects from the receiver’s content array.
Discussion
See removeObject: for a discussion of the semantics of removing objects when using Core Data.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hremoveObjects:
Removes objects from the receiver’s content collection.
Special Considerations
See removeObject: for a discussion of the semantics of removing objects when using Core Data.
Availability
- Available in OS X v10.3 and later.
Declared In
NSArrayController.hremoveObjectsAtArrangedObjectIndexes:
Removes the objects at the specified indexes in the receiver’s arranged objects from the content array.
Discussion
See removeObject: for a discussion of the semantics of removing objects when using Core Data.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hremoveSelectedObjects:
Removes objects from the receiver’s current selection, returning YES if the selection was changed.
Discussion
Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hremoveSelectionIndexes:
Removes the object as the specified indexes from the receiver’s current selection, returning YES if the selection was changed.
Discussion
Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hselectedObjects
Returns an array containing the receiver’s selected objects.
Discussion
This property is observable using key-value observing.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hselectionIndex
Returns the index of the first object in the receiver’s selection.
Return Value
The index of the first object in the receiver’s selection, or NSNotFound if there is no selection.
Discussion
This property is observable using key-value observing.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hselectionIndexes
Returns an index set containing the indexes of the receiver’s currently selected objects in the content array.
Return Value
An index set containing the indexes of the receiver’s currently selected objects in the content array.
Discussion
This property is observable using key-value observing.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hselectNext:
Selects the next object, relative to the current selection, in the receiver’s arranged content.
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) can provide feedback as a sheet.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hselectPrevious:
Selects the previous object, relative to the current selection, in the receiver’s arranged content.
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) can provide feedback as a sheet.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hselectsInsertedObjects
Returns whether the receiver automatically selects inserted objects.
Return Value
YES if the receiver automatically selects inserted objects, otherwise NO.
Discussion
The default is YES.
This property is observable using key-value observing.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hsetAlwaysUsesMultipleValuesMarker:
Sets whether the receiver always returns the multiple values marker when multiple objects are selected.
Parameters
- flag
If
YES, the receiver always returns the multiple values marker when multiple objects are selected, even if they have the same value.
Discussion
Setting flag to YES can increase performance if your application doesn’t allow editing multiple values. The default is NO.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSArrayController.hsetAutomaticallyPreparesContent:
Sets whether the receiver automatically creates and inserts new content objects automatically.
Parameters
- flag
If
YES, the receiver automatically prepares its content.
Discussion
If flag is YES and the receiver is not using a managed object context, prepareContent is used to create the content object.
If flag is YES and a managed object context is set, the initial content is fetched from the managed object context using the current fetch predicate. The controller also registers as an observer of its managed object context. It then tracks insertions and deletions of its entity using the context's notifications, and updates its content array as appropriate.
Setting flag to YES is the same as checking the “Automatically Prepares Content” option in the Interface Builder controller inspector.
setAutomaticallyRearrangesObjects:
Sets whether or not the receiver automatically rearranges its content to correspond to the current sort descriptors and filter predicates.
Parameters
- flag
A Boolean value that indicates whether the receiver automatically rearranges its content (
YES) or not (NO).
Discussion
The default is NO.
Availability
- Available in OS X v10.5 and later.
Declared In
NSArrayController.hsetAvoidsEmptySelection:
Sets whether the receiver attempts to avoid an empty selection.
Parameters
- flag
If
YES, the receiver maintains a selection unless there are no objects in the content array.
Discussion
The default is YES.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hsetClearsFilterPredicateOnInsertion:
Sets whether the receiver automatically clears an existing filter predicate when a new object is inserted or added to the content array.
Parameters
- flag
If
YES, the receiver automatically clears an existing filter predicate when a new object is inserted or added to the content array.
Discussion
The default is YES.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSArrayController.hsetFilterPredicate:
Sets the predicate used to filter the contents of the receiver.
Parameters
- filterPredicate
The predicate used to filter the contents of the receiver.
Discussion
If filterPredicate is nil, any existing filter predicate is removed.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSArrayController.hsetPreservesSelection:
Sets whether the receiver attempts to preserve selection when the content changes.
Parameters
- flag
If
YES, the receiver attempts to preserve selection when the content changes.
Discussion
The default is YES.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hsetSelectedObjects:
Sets objects as the receiver’s current selection, returning YES if the selection was changed.
Discussion
Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hsetSelectionIndex:
Sets the receiver’s selection to the given index, and returns a Boolean value that indicates whether the selection was changed.
Parameters
- index
The index for the selection.
Return Value
YES if the selection was changed, otherwise NO.
Discussion
Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hsetSelectionIndexes:
Sets the receiver’s selection indexes and returns a Boolean value that indicates whether the selection changed.
Parameters
- indexes
The set of selection indexes for the receiver.
Return Value
YES if the selection was changed, otherwise NO.
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.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hsetSelectsInsertedObjects:
Sets whether the receiver will automatically select objects as they are inserted.
Parameters
- flag
If
YESthen items will be selected upon insertion.
Discussion
The default is YES.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hsetSortDescriptors:
Sets the sort descriptors for the receiver.
Parameters
- sortDescriptors
An array of
NSSortDescriptorobjects, used by the receiver to arrange its content.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.hsortDescriptors
Returns the receiver's array of sort descriptors.
Return Value
The array of NSSortDescriptor objects used by the receiver to arrange its content.
Discussion
This property is observable using key-value observing.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSArrayController.h© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-11-17)