<!--
{
  "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/init(fetchDescriptor:sectionBy:modelContext:isolation:)-9kg1q",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftData"
    ],
    "preciseIdentifier" : "s:9SwiftData15ResultsObserverCAASSRs_rlE15fetchDescriptor9sectionBy12modelContext9isolationACyxSSGAA05FetchF0VyxG_s7KeyPathCyxSSSgGAA05ModelJ0CScA_pSgYitKcfc"
  },
  "title" : "init(fetchDescriptor:sectionBy:modelContext:isolation:)"
}
-->

# init(fetchDescriptor:sectionBy:modelContext:isolation:)

Creates a new observer with the given fetch descriptor, an optional String section key path, and a model context.

```
convenience init(fetchDescriptor: FetchDescriptor<Element> = FetchDescriptor<Element>(), sectionBy: KeyPath<Element, String?>, modelContext: ModelContext, isolation: isolated (any Actor)? = #isolation) throws
```

## Parameters

`fetchDescriptor`

The descriptor defining the fetch criteria.

`sectionBy`

A key path on the element type that returns an optional section name.

`modelContext`

The model context to fetch from and observe for changes.

## Discussion

Use this initializer when the section key path points to an optional `String` property.
Elements whose section value is `nil` are grouped into a section with an empty name.

> Throws: An error if the initial fetch fails.

---

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)