<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "tvOS: -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UICollectionViewDataSource",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UICollectionViewDataSource"
  },
  "title" : "UICollectionViewDataSource"
}
-->

# UICollectionViewDataSource

The methods adopted by the object you use to manage data and provide cells for a collection view.

```
@MainActor protocol UICollectionViewDataSource : NSObjectProtocol
```

## Overview

A data source object manages the data in your collection view. It represents your app’s data model and vends information to the collection view as needed. It also creates and configures the cells and supplementary views that the collection view uses to display your data.

A collection view data source must conform to the [`UICollectionViewDataSource`](/documentation/UIKit/UICollectionViewDataSource) protocol. You can use a [`UICollectionViewDiffableDataSource`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa) object as your data source object, which already conforms to this protocol.

Alternatively, you can create a custom data source object by adopting the [`UICollectionViewDataSource`](/documentation/UIKit/UICollectionViewDataSource) protocol. At a minimum, all data source objects must implement the [`collectionView(_:numberOfItemsInSection:)`](/documentation/UIKit/UICollectionViewDataSource/collectionView(_:numberOfItemsInSection:)) and [`collectionView(_:cellForItemAt:)`](/documentation/UIKit/UICollectionViewDataSource/collectionView(_:cellForItemAt:)) methods. These methods are responsible for returning the number of items in the collection view along with the items themselves. The remaining methods of the protocol are optional and only needed if your collection view organizes items into multiple sections or provides headers and footers for a given section.

When you configure the collection view object, assign your data source to its [`dataSource`](/documentation/UIKit/UICollectionView/dataSource) property. For more information about how a collection view works with its data source to present content, see [`UICollectionView`](/documentation/UIKit/UICollectionView).

## Topics

### Getting item and section metrics

[`-  collectionView:numberOfItemsInSection:`](/documentation/UIKit/UICollectionViewDataSource/collectionView(_:numberOfItemsInSection:))

Asks your data source object for the number of items in the specified section.

[`-  numberOfSectionsInCollectionView:`](/documentation/UIKit/UICollectionViewDataSource/numberOfSections(in:))

Asks your data source object for the number of sections in the collection view.

### Getting views for items

[`-  collectionView:cellForItemAtIndexPath:`](/documentation/UIKit/UICollectionViewDataSource/collectionView(_:cellForItemAt:))

Asks your data source object for the cell that corresponds to the specified item in the collection view.

[`-  collectionView:viewForSupplementaryElementOfKind:atIndexPath:`](/documentation/UIKit/UICollectionViewDataSource/collectionView(_:viewForSupplementaryElementOfKind:at:))

Asks your data source object to provide a supplementary view to display in the collection view.

### Reordering items

[`-  collectionView:canMoveItemAtIndexPath:`](/documentation/UIKit/UICollectionViewDataSource/collectionView(_:canMoveItemAt:))

Asks your data source object whether the specified item can move to another location in the collection view.

[`-  collectionView:moveItemAtIndexPath:toIndexPath:`](/documentation/UIKit/UICollectionViewDataSource/collectionView(_:moveItemAt:to:))

Tells your data source object to move the specified item to its new location.

### Configuring an index

[`-  indexTitlesForCollectionView:`](/documentation/UIKit/UICollectionViewDataSource/indexTitles(for:))

Asks the data source to return the titles for the index items to display for the collection view.

[`-  collectionView:indexPathForIndexTitle:atIndex:`](/documentation/UIKit/UICollectionViewDataSource/collectionView(_:indexPathForIndexTitle:at:))

Asks the data source to return the index path of a collection view item that corresponds to one of your index entries.

## Relationships

### Conforming Types

[`UICollectionViewDiffableDataSourceReference`](/documentation/UIKit/UICollectionViewDiffableDataSourceReference)

[`UICollectionViewController`](/documentation/UIKit/UICollectionViewController)

[`UICollectionViewDiffableDataSource-9tqpa`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa)

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)