Mac Developer Library

Developer

AppKit Framework Reference NSTextAttachment Class Reference

Options
Deployment Target:

On This Page
Language:

NSTextAttachment

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.

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

    init(fileWrapper aWrapper: 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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s file wrapper.

    Declaration

    Swift

    var fileWrapper: NSFileWrapper?

    Objective-C

    @property(strong) NSFileWrapper *fileWrapper

    Parameters

    aWrapper

    The file wrapper for the receiver.

    Discussion

    The file wrapper holds the contents of the attached file.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – fileWrapper

  • Returns the receiver’s file wrapper.

    Declaration

    Swift

    var fileWrapper: NSFileWrapper?

    Objective-C

    @property(strong) NSFileWrapper *fileWrapper

    Return Value

    The receiver’s file wrapper.

    Discussion

    The file wrapper holds the contents of the attached file.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    var attachmentCell: NSTextAttachmentCellProtocol!

    Objective-C

    @property(strong) id<NSTextAttachmentCell> attachmentCell

    Parameters

    aCell

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    var attachmentCell: NSTextAttachmentCellProtocol!

    Objective-C

    @property(strong) 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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    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.