CKSectionedArrayController Class Reference

Inherits from NSObject
Declared in CKSectionedArrayController.h

Overview

Manages an array of objects bucketed into sections. Suitable for using to manage the backing data for a UITableView or UICollectionView.

The array controller is mutated by constructing a list of commands: insert, remove, update, which are then applied in a single “transaction” to the array controller. In response to a mutation, the array controller reutrns a list of changes that can be used to mutate a UITableView or UICollectionView.

We make only minimal attempts to ensure that the indexes (index paths) passed are at all “valid”, duplicate commands will throw NSInvalidArgumentExceptions. Out-of-bounds access, even with commands passed to -applyChangeset: will also throw.

We’ve wholesale copied the contract of UITableView mutations (because it’s simple to implement and you might already know it). See -applyChangeset:

See also CKArrayControllerChangeset.h.

– enumerateObjectsUsingBlock:

Enumerates over all items in ascending order of index path.

- (void)enumerateObjectsUsingBlock:(CKSectionedArrayControllerEnumerator)enumerator

Parameters

enumerator

A block invoked for each item in the receiver.

Declared In

CKSectionedArrayController.h

– enumerateObjectsInSectionAtIndex:usingBlock:

Enumerates over all items in the given section in ascending order of index path.

- (void)enumerateObjectsInSectionAtIndex:(NSInteger)sectionIndex usingBlock:(CKSectionedArrayControllerEnumerator)enumerator

Parameters

enumerator

A block invoked for each item in the section in the receiver.

Declared In

CKSectionedArrayController.h

– applyChangeset:

Iterates over the input commands and changes our internal sections array accordingly.

- (CKArrayControllerOutputChangeset)applyChangeset:(CKArrayControllerInputChangeset)changeset

Parameters

changeset

The commands (create, update, delete) to apply to our array controller.

Return Value

A changeset that describes operations that we can directly apply to a UITableView or UICollectionView.

Discussion

The indexes in the input changeset are applied to the reciever in the following order:

1) item updates 2) item removals 3) section removals 4) section insertions 5) item insertions

To do so: 1) index paths for updates and removals MUST be relative to the initial state of the array controller. 2) index paths for insertions MUST be relative post-application of removal operations.

The obvious side-effect of this: 1) Updating an item and subsequently removing the section in which the item resides is wasteful.

Declared In

CKSectionedArrayController.h