Contents

NSTextAttachment

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

Declaration

class NSTextAttachment

Overview

The NSAttributedString class uses text attachment objects as the values for attachment attributes (stored in the attributed string under the attachment key in Swift or the NSAttachmentAttributeName key in Objective-C).

A text attachment object contains either an NSData object or an FileWrapper object, which in turn holds the contents of the attached file. The properties of this class configure the appearance of the text attachment in your interface. In macOS, the text attachment also uses a cell object that conforms to the NSTextAttachmentCellProtocol protocol to draw the image that represents the text and handles mouse events. For more information about text attachments, see the NSAttributedString and NSTextView.

In macOS 12 and iOS 15 and later, NSTextAttachmentViewProvider and NSTextAttachmentLayout provide additional capabilities to represent document locations in terms of an NSTextLocation or an NSTextRange, and provide support for view-based text attachments.

Topics

Initializing a text attachment

Defining the attachment’s contents

Setting the attachment cell

Constants

Convenience methods

Initializers

See Also

Attachments