NSTextAttachment Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.0 and later.
Declared in
NSTextAttachment.h
Companion guides
Related sample code

Overview

NSTextAttachment objects are used by the NSAttributedString class cluster as the values for attachment attributes (stored in the attributed string under the key named NSAttachmentAttributeName). The objects you create with this class are referred to as text attachment objects, or when no confusion will result, as text attachments or merely attachments.

A text attachment object contains an NSFileWrapper object, which in turn holds the contents of the attached file. It also uses a cell object conforming to the NSTextAttachmentCell protocol to draw and handle mouse events. Most of the behavior of a text attachment is relegated to the file wrapper and the attachment cell. See the corresponding class and protocol specifications for more information.

See the NSAttributedString and NSTextView class specifications for general information on text attachments.

Adopted Protocols

NSCoding

Tasks

Initializing an NSTextAttachment Object

Setting the File Wrapper

Setting the Attachment Cell

Instance Methods

attachmentCell

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

- (id < NSTextAttachmentCell >)attachmentCell
Return Value

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

Discussion

An NSTextAttachment object by default uses an NSTextAttachmentCell object that displays the attached file’s icon, or its contents if the file contains an image.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTextAttachment.h

fileWrapper

Returns the receiver’s file wrapper.

- (NSFileWrapper *)fileWrapper
Return Value

The receiver’s file wrapper.

Discussion

The file wrapper holds the contents of the attached file.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSTextAttachment.h

initWithFileWrapper:

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

- (id)initWithFileWrapper:(NSFileWrapper *)aWrapper
Parameters
aWrapper

The file wrapper for the receiver.

Return Value

The receiver initialized to contain aWrapper and use an NSTextAttachmentCell as its attachment cell.

Discussion

This method is the designated initializer for the NSTextAttachment class.

If aWrapper contains an image file that the receiver can interpret as an NSImage object, sets the attachment cell’s image to the NSImage rather than to the icon of aWrapper.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSTextAttachment.h

setAttachmentCell:

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

- (void)setAttachmentCell:(id < NSTextAttachmentCell >)aCell
Parameters
aCell

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

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTextAttachment.h

setFileWrapper:

Sets the receiver’s file wrapper.

- (void)setFileWrapper:(NSFileWrapper *)aWrapper
Parameters
aWrapper

The file wrapper for the receiver.

Discussion

The file wrapper holds the contents of the attached file.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTextAttachment.h

Constants

Attachment Character

This character is used to denote an attachment.

enum {
   NSAttachmentCharacter = 0xfffc
};
Constants
NSAttachmentCharacter

Specifies a character that denotes an attachment.

Available in OS X v10.0 and later.

Declared in NSTextAttachment.h.

Declared In
NSTextAttachment.h