<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSTextContentStorage",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextContentStorage"
  },
  "title" : "NSTextContentStorage"
}
-->

# NSTextContentStorage

A concrete object for managing your view’s text content and generating the text elements necessary for layout.

```
class NSTextContentStorage
```

## Overview

An [`NSTextContentStorage`](/documentation/UIKit/NSTextContentStorage) object provides the backing store for a view that contains text. This object stores the text in an attributed string object, and defaults to using an [`NSTextStorage`](/documentation/UIKit/NSTextStorage) object. It also maps portions of the text to [`NSTextElement`](/documentation/UIKit/NSTextElement) objects to organize the text into paragraphs, lists, and other common element types found in text content. During layout, TextKit uses these elements to lay out and render the text in your view.

The standard system views use an [`NSTextContentStorage`](/documentation/UIKit/NSTextContentStorage) object to manage their text content. When building a custom text view, use this type to store the text for your view. [`NSTextContentStorage`](/documentation/UIKit/NSTextContentStorage) works with an associated [`NSTextLayoutManager`](/documentation/UIKit/NSTextLayoutManager) to lay out your view’s text. When someone inserts new text or edits the existing text, call the [`performEditingTransaction(_:)`](/documentation/UIKit/NSTextContentManager/performEditingTransaction(_:)) method and use a block to modify the contents of the [`attributedString`](/documentation/UIKit/NSTextContentStorage/attributedString) property. Wrapping your edits in an edit transaction lets the rest of the text system respond to those changes.

TextKit uses the abstract [`NSTextLocation`](/documentation/UIKit/NSTextLocation) protocol to identify locations within text. [`NSTextContentStorage`](/documentation/UIKit/NSTextContentStorage) manager provides its own implementation of this protocol to represent locations within its storage object. To get the start and end locations, access the object’s [`documentRange`](/documentation/UIKit/NSTextElementProvider/documentRange) property and use them to create new location objects. If you provide your own implementation of the [`NSTextLocation`](/documentation/UIKit/NSTextLocation) protocol to manage locations in your content, subclass [`NSTextContentManager`](/documentation/UIKit/NSTextContentManager) and implement your own storage object to support those locations.

## Topics

### Managing the stored text

[`attributedString`](/documentation/UIKit/NSTextContentStorage/attributedString)

An attributed string that contains the contents of the document.

### Accessing paragraphs

[`delegate`](/documentation/UIKit/NSTextContentStorage/delegate)

The delegate for the content storage object.

[`NSTextContentStorageDelegate`](/documentation/UIKit/NSTextContentStorageDelegate)

The optional methods that delegates of content storage objects implement to handle content processing.

### Finding ranges, locations, and offsets

[`location(_:offsetBy:)`](/documentation/UIKit/NSTextContentStorage/location(_:offsetBy:))

Returns a new text location object based on an existing location and offset you provide.

[`offset(from:to:)`](/documentation/UIKit/NSTextContentStorage/offset(from:to:))

Returns the number of characters between the specified locations.

[`adjustedRange(from:forEditingTextSelection:)`](/documentation/UIKit/NSTextContentStorage/adjustedRange(from:forEditingTextSelection:))

Returns the text range, if any, in the backing store that required manual adjustment after editing.

### Managing text elements

[`textElement(for:)`](/documentation/UIKit/NSTextContentStorage/textElement(for:))

Returns the text element corresponding to object’s attributed string.

[`attributedString(for:)`](/documentation/UIKit/NSTextContentStorage/attributedString(for:))

Returns a new attributed string for the text element.

### Notifications

[`NSTextContentStorageUnsupportedAttributeAddedNotification`](/documentation/UIKit/NSTextContentStorageUnsupportedAttributeAddedNotification)

Posted by `NSTextContentStorage` when a text attribute unsupported by `NSTextContentStorage` is added to the underlying text storage.



---

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)