Class

NSTextStorage

The fundamental storage mechanism of TextKit.

Declaration

@interface NSTextStorage : NSMutableAttributedString

Overview

NSTextStorage is a semi concrete subclass of NSMutableAttributedString that adds behavior for managing a set of client NSLayoutManager objects. A text storage object notifies its layout managers of changes to its characters or attributes, which lets the layout managers redisplay the text as needed.

A text storage object can be accessed from any thread of your app, but your app must guarantee access from only one thread at a time.

Subclassing Notes

The NSTextStorage class implements change management (via the beginEditing and endEditing methods), verification of attributes, delegate handling, and layout management notification. The one aspect it does not implement is managing the actual attributed string storage, which subclasses manage by overriding the two NSAttributedString primitives:

string

attributesAtIndex:effectiveRange:

Subclasses must also override two NSMutableAttributedString primitives:

replaceCharactersInRange:withString:

setAttributes:range:

These primitives should perform the change, then call edited:range:changeInLength: to let the parent class know what changes were made.

Topics

Accessing Layout Managers

layoutManagers

The layout managers associated with the text storage object.

- addLayoutManager:

Adds a layout manager to the receiver’s set of layout managers.

- removeLayoutManager:

Removes a layout manager from the receiver’s set of layout managers.

Handling Text Editing Messages

- edited:range:changeInLength:

Tracks changes made to the receiver, allowing the text storage to record the full extent of changes made.

- ensureAttributesAreFixedInRange:

Ensures that attributes are fixed in the given range.

fixesAttributesLazily

A Boolean value indicating whether the text storage object fixes attributes lazily.

- invalidateAttributesInRange:

Invalidates attributes in the specified range.

- processEditing

Cleans up changes made to the receiver and notifies its delegate and layout managers of changes.

Determining the Nature of Changes

editedMask

A mask describing the kinds of edits pending for the text storage object.

editedRange

The range of text containing changes.

changeInLength

The difference between the current length of the edited range and its length before editing began.

Setting the delegate

delegate

The delegate for the text storage object.

Accessing Scriptable Properties

attributeRuns

The text storage contents represented as an array of attribute runs.

paragraphs

The text storage contents represented as an array of paragraphs.

words

The text storage contents represented as an array of words.

characters

The text storage contents represented as an array of characters.

font

The font associated with the text storage.

foregroundColor

The color to use when drawing the text.

Constants

NSTextStorageEditActions

Constants indicating the types of changes that were made.

Notifications

NSTextStorageDidProcessEditingNotification

Posted after a text storage finishes processing edits in processEditing.

NSTextStorageWillProcessEditingNotification

Posted before a text storage finishes processing edits in processEditing.

Relationships

Conforms To

See Also

Data

NSTextStorageDelegate

A set of optional methods implemented by delegates of NSTextStorage objects to handle text-edit processing.

NSTextContainer

A region where text is laid out.

NSAttributedString

A string that has associated attributes (such as visual style, hyperlinks, or accessibility data) for portions of its text.