<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextElementProvider",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextElementProvider"
  },
  "title" : "NSTextElementProvider"
}
-->

# NSTextElementProvider

A protocol the text content manager and its concrete subclasses conform to, which defines the interface for interacting with custom content types of a text document.

```
protocol NSTextElementProvider : NSObjectProtocol
```

## Topics

### Accessing the range of the text element

[`var documentRange: NSTextRange`](/documentation/AppKit/NSTextElementProvider/documentRange)

Describes the starting and ending locations for the document.

### Accessing and updating the text

[`func enumerateTextElements(from: (any NSTextLocation)?, options: NSTextContentManager.EnumerationOptions, using: (NSTextElement) -> Bool) -> (any NSTextLocation)?`](/documentation/AppKit/NSTextElementProvider/enumerateTextElements(from:options:using:))

Enumerates text elements starting at the text location you provide.

[`struct EnumerationOptions`](/documentation/AppKit/NSTextLayoutFragment/EnumerationOptions)

Values that describe options for enumerating text layout fragments.

[`func location(any NSTextLocation, offsetBy: Int) -> (any NSTextLocation)?`](/documentation/AppKit/NSTextElementProvider/location(_:offsetBy:))

Returns a new location from location with offset you provide.

[`func replaceContents(in: NSTextRange, with: [NSTextElement]?)`](/documentation/AppKit/NSTextElementProvider/replaceContents(in:with:))

Replaces the characters specified by range with the text elements you provide.

### Adjusting the range of the text element

[`func adjustedRange(from: NSTextRange, forEditingTextSelection: Bool) -> NSTextRange?`](/documentation/AppKit/NSTextElementProvider/adjustedRange(from:forEditingTextSelection:))

A method you implement if the location backing store requires manual adjustment after editing.

[`func offset(from: any NSTextLocation, to: any NSTextLocation) -> Int`](/documentation/AppKit/NSTextElementProvider/offset(from:to:))

Returns the offset between the two specified locations.

### Controlling synchronization with the backing store

[`func synchronizeToBackingStore((((any Error)?) -> Void)?)`](/documentation/AppKit/NSTextElementProvider/synchronizeToBackingStore(_:))

Synchronizes changes to the backing store.

## Relationships

### Conforming Types

[`NSTextContentManager`](/documentation/AppKit/NSTextContentManager)

[`NSTextContentStorage`](/documentation/AppKit/NSTextContentStorage)

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

---

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)