Contents

UILocalizedIndexedCollation

An object that organizes, sorts, and localizes the data for a table view that has a section index.

Declaration

@MainActor class UILocalizedIndexedCollation

Overview

Use a UILocalizedIndexedCollation object in conjunction with your table’s data source object to sort and manage the data in an indexed table view. An index is an ideal way for users to navigate a table view containing sequential content. For example, the Contacts app sorts contacts alphabetically and displays an index for navigating those contacts quickly. You use the collation object as the source of the table’s section titles and index titles in your table view. You also use it to sort items in each section of your table.

To prepare the data for a section index, create an indexed-collation object and call section(for:collationStringSelector:) for each model object to be indexed. That method determines the section in which each of these objects should appear and returns an integer that identifies the section. The table-view controller then puts each object in a local array for its section. For each section array, the controller calls the sortedArray(from:collationStringSelector:) method to sort all of the objects in the section. The indexed-collation object is now the data store that the table-view controller uses to provide section-index data to the table view, as shown in the following example code.

Topics

Getting the shared instance

Preparing the sections and section indexes

Providing section index data to the table view

See Also

Data