<!--
{
  "availability" : [
    "macOS: 10.11.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSCollectionViewDataSource/numberOfSections(in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSCollectionViewDataSource(im)numberOfSectionsInCollectionView:"
  },
  "title" : "numberOfSections(in:)"
}
-->

# numberOfSections(in:)

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

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

## Parameters

`collectionView`

The collection view requesting the information.

## Return Value

The number of sections in the specified collection view.

## 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.

---

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)