Mac Developer Library

Developer

AppKit Framework Reference NSTextAttachment Class Reference

Options
Deployment Target:

On This Page
Language:

NSTextAttachment

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.

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

    Declaration

    Swift

    convenience init(fileWrapper fileWrapper: NSFileWrapper?)

    Objective-C

    - (instancetype)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.

  • The receiver’s file wrapper.

    Declaration

    Swift

    var fileWrapper: NSFileWrapper?

    Objective-C

    @property(strong) NSFileWrapper *fileWrapper

    Discussion

    The file wrapper holds the contents of the attached file.

    Availability

    Available in OS X v10.0 and later.

  • This character is used to denote an attachment.

    Declaration

    Swift

    var NSAttachmentCharacter: Int { get }

    Objective-C

    enum { NSAttachmentCharacter = 0xfffc };

    Constants

    • NSAttachmentCharacter

      NSAttachmentCharacter

      Specifies a character that denotes an attachment.

      Available in OS X v10.0 and later.