<!--
{
  "documentType" : "article",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/textkit",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "TextKit"
}
-->

# TextKit

Manage text storage and perform custom layout of text-based content in your app’s views.

## Discussion

TextKit is a powerful and versatile text layout and rendering engine available in AppKit and UIKit. It provides several classes to control the layout of text, including [`NSTextLayoutManager`](/documentation/AppKit/NSTextLayoutManager), [`NSTextContentStorage`](/documentation/AppKit/NSTextContentStorage), [`NSTextViewportLayoutController`](/documentation/AppKit/NSTextViewportLayoutController), and [`NSTextContainer`](/documentation/AppKit/NSTextContainer).

In AppKit, you can use [`NSTextView`](/documentation/AppKit/NSTextView), which packages TextKit capabilities to provide a convenient text rendering and editing experience. [`NSTextView`](/documentation/AppKit/NSTextView) uses [`NSTextContentStorage`](/documentation/AppKit/NSTextContentStorage) as the text backing store manager. [`NSTextContentStorage`](/documentation/AppKit/NSTextContentStorage) uses an instance of [`NSTextStorage`](/documentation/AppKit/NSTextStorage) as the backing store, which is a subclass of <doc://com.apple.documentation/documentation/Foundation/NSMutableAttributedString>. For an example, see <doc://com.apple.documentation/documentation/UIKit/enriching-your-text-in-text-views>.

Alternatively, you can build custom text views using your own [`NSView`](/documentation/AppKit/NSView) by rendering text provided by the TextKit text engine. Use [`NSTextContentStorage`](/documentation/AppKit/NSTextContentStorage) if you want an <doc://com.apple.documentation/documentation/Foundation/NSAttributedString>-related storage type, or subclass [`NSTextContentManager`](/documentation/AppKit/NSTextContentManager) to use your own. For an example, see <doc://com.apple.documentation/documentation/UIKit/using-textkit-2-to-interact-with-text>.

When using [`NSTextView`](/documentation/AppKit/NSTextView), access the TextKit engine through the view’s [`textLayoutManager`](/documentation/AppKit/NSTextView/textLayoutManager), [`textContainer`](/documentation/AppKit/NSTextView/textContainer), and [`textStorage`](/documentation/AppKit/NSTextView/textStorage) properties. [`NSTextView`](/documentation/AppKit/NSTextView) provides access to two layout engines: the modern [`textLayoutManager`](/documentation/AppKit/NSTextView/textLayoutManager), which uses [`NSTextLayoutManager`](/documentation/AppKit/NSTextLayoutManager), and the legacy [`layoutManager`](/documentation/AppKit/NSTextView/layoutManager), which uses [`NSLayoutManager`](/documentation/AppKit/NSLayoutManager). Use [`textLayoutManager`](/documentation/AppKit/NSTextView/textLayoutManager) for better performance, and support for international languages. Because TextKit classes are available in both AppKit and UIKit, the same techniques apply across macOS, iOS, iPadOS, tvOS, and visionOS.

## Topics

### Text management

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

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

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

An abstract class that defines the interface and a default implementation for managing the text document contents.

  <doc://com.apple.documentation/documentation/Foundation/NSAttributedString>

  <doc://com.apple.documentation/documentation/Foundation/NSMutableAttributedString>

### Text management

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

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

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

An abstract class that defines the interface and a default implementation for managing the text document contents.

  <doc://com.apple.documentation/documentation/Foundation/NSAttributedString>

  <doc://com.apple.documentation/documentation/Foundation/NSMutableAttributedString>

[TextKit string attributes](/documentation/AppKit/textkit-string-attributes)

AppKit-specific keys and values for displaying text and managing documents.

### Formatting and attributes

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

The paragraph or ruler attributes for an attributed string.

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

An object for changing the values of the subattributes in a paragraph style attribute.

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

A tab in a paragraph.

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

A section of text that forms a single list.

### Tables

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

An object that represents a text table as a whole.

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

A text block that appears as a cell in a text table.

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

A block of text laid out in a subregion of the text container.

### Content elements

  <doc://com.apple.documentation/documentation/UIKit/enriching-your-text-in-text-views>

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

A class that represents a single paragraph backed by an attributed string as the contents.

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

A class that represents a text list node.

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

An abstract base class that represents the smallest units of text layout such as paragraphs or attachments.

[`NSTextElementProvider`](/documentation/AppKit/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.

### Location and selection

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

A class that represents a contiguous range between two locations inside document contents.

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

A class that represents a single logical selection context that corresponds to an insertion point.

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

An interface you use to expose methods for obtaining results from actions performed on text selections.

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

An object that coordinates text selection behavior for custom text views.

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

An interface you implement that represents an abstract location inside your document’s content.

### Layout

  <doc://com.apple.documentation/documentation/UIKit/using-textkit-2-to-interact-with-text>

  <doc://com.apple.documentation/documentation/UIKit/managing-viewport-layout-and-attachment-reuse-in-a-text-view-subclass>

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

The primary class that you use to manage text layout and presentation for custom text displays.

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

A region where text layout occurs.

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

A class that represents the layout fragment typically corresponding to a rendering surface, such as a layer or view subclass.

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

A class that represents a line fragment as a single textual layout and rendering unit inside a text layout fragment.

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

Manages the layout process inside the viewport interacting with its delegate.

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

A set of methods that define the orientation of text for an object.

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

A protocol that identifies a view or layer as a drawable element for a text layout fragment.

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

A protocol that lets you use an object to identify a rendering surface when storing or retrieving it.

### Attachments

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

The values for the attachment characteristics of attributed strings and related objects.

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

A container object that associates a text attachment at a particular document location with a view object.

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

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

A data object for an emoji-like image that can appear in attributed text.

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

A set of methods that defines the interface to text attachment objects from a layout manager.

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

A set of methods that defines the interface to attachment objects from a text layout manager.

[`NSTextAttachmentCell`](/documentation/AppKit/NSTextAttachmentCell-swift.class)

An object that implements the functionality of the text attachment cell protocol.

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

A set of methods that declares the interface for objects that draw text attachment icons and handle mouse events on their icons.

### Glyphs

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

The type used to specify glyphs.

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

A set of methods that a glyph storage object must implement to interact properly with [`NSGlyphGenerator`](/documentation/AppKit/NSGlyphGenerator).

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

An object that performs the initial, nominal glyph generation phase in the layout process.

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

A glyph attribute in an attributed string.

[Reserved Glyph Codes](/documentation/AppKit/reserved-glyph-codes)

These constants define reserved glyph codes.

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

The font rendering mode.

### TextKit 1

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

The fundamental storage mechanism of TextKit that contains the text managed by the system.

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

An object that coordinates the layout and display of text characters.

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

A concrete typesetter object that places glyphs during the text layout process.

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

An abstract class that performs various type layout tasks.

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

Values that describe the progression of text on a page.

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

The direction in which a line moves.



---

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)