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

# collectionView(_:numberOfItemsInSection:)

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

```
@MainActor func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int
```

## Parameters

`collectionView`

The collection view requesting the information.

`section`

The index number of the section. Section indexes are zero based.

## Return Value

The number of items in the specified section.

## Discussion

All data source objects must implement this method. Your implementation should quickly return the number of items in the specified section.

Make sure the number of items you return is accurate. The [`collectionView(_:itemForRepresentedObjectAt:)`](/documentation/AppKit/NSCollectionViewDataSource/collectionView(_:itemForRepresentedObjectAt:)) method of your data source object must be able to provide a visual representation for each item in the 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)