<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSCollectionViewLayout/layoutAttributesForInterItemGap(before:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCollectionViewLayout(im)layoutAttributesForInterItemGapBeforeIndexPath:"
  },
  "title" : "layoutAttributesForInterItemGap(before:)"
}
-->

# layoutAttributesForInterItemGap(before:)

Returns layout attributes for the inter-item gap at the specified location in your layout.

```
func layoutAttributesForInterItemGap(before indexPath: IndexPath) -> NSCollectionViewLayoutAttributes?
```

## Parameters

`indexPath`

The index path of the item that follows the inter-item gap. For a gap that follows the last item in the section, set the item property to the total number of items in the section.

## Return Value

A layout attributes object containing the layout information to apply to the inter-item gap, or `nil` if no attributes are available.

## Discussion

The default implementation of this method returns `nil`. Subclasses can override this method to provide layout attributes for inter-item gaps. In your implementation, use the specified index path to compute the location of the gap in collection view’s content. If the gap represents a valid location, use the [`init(forInterItemGapBefore:)`](/documentation/AppKit/NSCollectionViewLayoutAttributes/init(forInterItemGapBefore:)) class method of [`NSCollectionViewLayoutAttributes`](/documentation/AppKit/NSCollectionViewLayoutAttributes) to create a new layout attributes object and set the [`frame`](/documentation/AppKit/NSCollectionViewLayoutAttributes/frame) property to the rectangle you computed.

---

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)