---
title: "numberOfSections(in:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nscollectionviewdatasource/numberofsections(in:)"
---

# numberOfSections(in:)

Asks your data source object to provide the total number of sections.

## Declaration

```swift
@MainActor optional func numberOfSections(in collectionView: NSCollectionView) -> Int
```

## Parameters

- `collectionView`: The collection view requesting the information.

## Return Value

Return Value The number of sections in the specified collection view.

## Discussion

Discussion Implement this method when the organization of your data requires more than one section. If you do not implement this method, the collection view creates only one section.

## See Also

### Getting the Number of Sections and Items

- [collectionView(_:numberOfItemsInSection:)](appkit/nscollectionviewdatasource/collectionview(_:numberofitemsinsection:).md)
