<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftData",
  "identifier" : "/documentation/SwiftData/ResultsObserver/sections",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "SwiftData"
    ],
    "preciseIdentifier" : "s:9SwiftData15ResultsObserverC8sectionsAA09SectionedC0Vyxq_GSgvp"
  },
  "title" : "sections"
}
-->

# sections

The sections computed from the current results, grouped by [`sectionBy`](/documentation/SwiftData/ResultsObserver/sectionBy).

```
final var sections: SectionedResults<Element, SectionTitle>? { get set }
```

## Discussion

Returns `nil` if this observer was created without a `sectionBy` key path
(i.e. `SectionTitle == Never`).
When sectioning is enabled, returns a [`SectionedResults`](/documentation/SwiftData/SectionedResults) 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`](/documentation/SwiftData/ResultsObserver/sortBy) is mutated, ensuring results are
always contiguous within each 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)