---
title: sections
framework: swiftdata
role: symbol
role_heading: Instance Property
path: swiftdata/resultsobserver/sections
---

# sections

The sections computed from the current results, grouped by sectionBy.

## Declaration

```swift
final var sections: ResultsSectionCollection<Element, SectionName>? { get set }
```

## Discussion

Discussion Returns nil if this observer was created without a sectionBy key path (i.e. SectionName == Never). When sectioning is enabled, returns a ResultsSectionCollection of sections ordered by their first appearance in the sorted results. The sectionBy key path is automatically prepended as the first sort descriptor at initialization, and re-prepended if sortBy is mutated, ensuring results are always contiguous within each section.

## See Also

### Accessing observer properties

- [fetchDescriptor](swiftdata/resultsobserver/fetchdescriptor.md)
- [filterBy](swiftdata/resultsobserver/filterby.md)
- [modelContext](swiftdata/resultsobserver/modelcontext.md)
- [sortBy](swiftdata/resultsobserver/sortby.md)
- [sectionBy](swiftdata/resultsobserver/sectionby.md)
- [ResultsSectionCollection](swiftdata/resultssectioncollection.md)
