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

# sections

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

## Declaration

```swift
@MainActor @preconcurrency var sections: ResultsSectionCollection<Element, String> { get }
```

## Discussion

Discussion Section names are String-typed. Both KeyPath<Element, String> and KeyPath<Element, String?> section keys produce String names — nil values map to the empty-string section. Returns an empty collection when the query was not created with a sectionBy parameter. Access this from the query’s stored property using the underscore prefix: struct ItemList: View {     @Query(sort: \.category, sectionBy: \.category)     var items: [Item]

var body: some View {         List {             ForEach(_items.sections) { section in                 Section(section.name) {                     ForEach(section) { item in Text(item.name) }                 }             }         }     } }

## See Also

### Accessing sections

- [ResultsSectionCollection](swiftdata/resultssectioncollection.md)
