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


The NSAttributedString class cluster uses text attachment objects as the values for attachment attributes (stored in the attributed string under the key named attachment).

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 conforming to the NSTextAttachmentCellProtocol protocol to draw and handle mouse events.

For more information about text attachments, see the NSAttributedString and NSTextView.


Initializing an NSTextAttachment object

init(fileWrapper: FileWrapper?)

Initializes a newly allocated NSTextAttachment object to contain the given file wrapper.

init(data: Data?, ofType: String?)

Initializes a new NSTextAttachment object with the given data.

Defining the Contents

var bounds: CGRect

Defines the layout bounds of the receiver's graphical representation in the text coordinate system.

var contents: Data?

Defines the contents for the text attachment.

var fileType: String?

Defines the file type of the contents for the text attachment.

var image: UIImage?

Image representing the text attachment contents.

var fileWrapper: FileWrapper?

The receiver’s file wrapper.

Setting the attachment cell

var attachmentCell: NSTextAttachmentCellProtocol?

The object used to draw the icon for the receiver and to handle mouse events.


Attachment Character

A character that denotes an attachment.

See Also


protocol NSTextAttachmentContainer

A set of methods that defines the interface to text attachment objects from NSLayoutManager.