Mac Developer Library

Developer

AppKit Framework Reference NSText Class Reference

Options
Deployment Target:

On This Page
Language:

NSText

Class at a Glance

NSText declares the most general programmatic interface for objects that manage text. You usually use instances of its subclass, NSTextView.

NSText declares the most general programmatic interface for objects that manage text. You usually use instances of its subclass, NSTextView.

NSTextView extends the interface declared by NSText and provides much more sophisticated functionality than that declared in NSText.

NSText initialization creates an instance of a concrete subclass, such as NSTextView. Instances of any of these classes are generically called text objects.

Text objects are used by the Application Kit wherever text appears in interface objects: A text object draws the title of a window, the commands in a menu, the title of a button, and the items in a browser. Your application can also create text objects for its own purposes.

Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.
  • Returns the characters of the receiver’s text.

    Declaration

    Swift

    var string: String?

    Objective-C

    @property(copy) NSString *string

    Return Value

    The characters of the receiver’s text.

    Discussion

    For performance reasons, this method returns the current backing store of the text object. If you want to maintain a snapshot of this as you manipulate the text storage, you should make a copy of the appropriate substring.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setString:

  • Controls whether the receiver allows the user to edit its text.

    Declaration

    Swift

    var editable: Bool

    Objective-C

    @property(getter=isEditable) BOOL editable

    Parameters

    flag

    If flag is YEStrue, the receiver allows the user to edit text and attributes; if flag is NOfalse, it doesn’t.

    Discussion

    You can change the receiver’s text programmatically regardless of this setting. If the receiver is made editable, it’s also made selectable. NSText objects are by default editable.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • isEditable - isEditable Available in OS X v10.0 through OS X v10.9

    Returns a Boolean value that indicates whether the receiver allows the user to edit text, NOfalse if it doesn’t.

    Declaration

    Objective-C

    - (BOOL)isEditable

    Return Value

    YEStrue if the receiver allows the user to edit text, otherwise NOfalse.

    Discussion

    You can change the receiver’s text programmatically regardless of this setting.

    If the receiver is editable, it’s also selectable.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Controls whether the receiver allows the user to select its text.

    Declaration

    Swift

    var selectable: Bool

    Objective-C

    @property(getter=isSelectable) BOOL selectable

    Parameters

    flag

    If flag is YEStrue, the receiver allows the user to select text; if flag is NOfalse, it doesn’t.

    Discussion

    You can set selections programmatically regardless of this setting. If the receiver is made not selectable, it’s also made not editable. NSText objects are by default editable and selectable.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • isSelectable - isSelectable Available in OS X v10.0 through OS X v10.9

    Returns a Boolean value that indicates whether the receiver allows the user to select text, NOfalse if it doesn’t.

    Declaration

    Objective-C

    - (BOOL)isSelectable

    Return Value

    YEStrue if the receiver allows the user to select text, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Controls whether the receiver interprets Tab, Shift-Tab, and Return (Enter) as cues to end editing and possibly to change the first responder.

    Declaration

    Swift

    var fieldEditor: Bool

    Objective-C

    @property(getter=isFieldEditor) BOOL fieldEditor

    Parameters

    flag

    If flag is YEStrue, the receiver interprets Tab, Shift-Tab, and Return (Enter) as cues to end editing and possibly to change the first responder; if flag is NOfalse, it doesn’t, instead accepting these characters as text input.

    Discussion

    See the NSWindow class specification for more information on field editors. By default, NSText objects don’t behave as field editors.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • isFieldEditor - isFieldEditor Available in OS X v10.0 through OS X v10.9

    Returns a Boolean value that indicates whether the receiver interprets Tab, Shift-Tab, and Return (Enter) as cues to end editing and possibly to change the first responder.

    Declaration

    Objective-C

    - (BOOL)isFieldEditor

    Return Value

    YEStrue if the receiver interprets Tab, Shift-Tab, and Return (Enter) as cues to end editing and possibly to change the first responder; NOfalse if it accepts them as text input.

    Discussion

    See the NSWindow class specification for more information on field editors. By default, NSText objects don’t behave as field editors.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Controls whether the receiver allows the user to apply attributes to specific ranges of the text.

    Declaration

    Swift

    var richText: Bool

    Objective-C

    @property(getter=isRichText) BOOL richText

    Parameters

    flag

    If flag is YEStrue the receiver allows the user to apply attributes to specific ranges of the text; if flag is NOfalse it doesn’t.

    Discussion

    If flag is NOfalse, the receiver is also set not to accept dragged files. Subclasses may or may not let the user apply multiple attributes to the text and accept drag files by default.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • isRichText - isRichText Available in OS X v10.0 through OS X v10.9

    Returns a Boolean value that indicates whether the receiver allows the user to apply attributes to specific ranges of the text.

    Declaration

    Objective-C

    - (BOOL)isRichText

    Return Value

    YEStrue if the receiver allows the user to apply attributes to specific ranges of the text, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Controls whether the receiver allows the user to import files by dragging.

    Declaration

    Swift

    var importsGraphics: Bool

    Objective-C

    @property BOOL importsGraphics

    Parameters

    flag

    If flag is YEStrue, the receiver allows the user to import files by dragging; if flag is NOfalse, it doesn’t.

    Discussion

    If the receiver is set to accept dragged files, it’s also made a rich text object. Subclasses may or may not accept dragged files by default.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value that indicates whether the receiver allows the user to import files by dragging.

    Declaration

    Swift

    var importsGraphics: Bool

    Objective-C

    @property BOOL importsGraphics

    Return Value

    YEStrue if the receiver allows the user to import files by dragging, otherwise NOfalse.

    Discussion

    A text object that accepts dragged files is also a rich text object.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Controls whether the receiver uses the Font panel and Font menu.

    Declaration

    Swift

    var usesFontPanel: Bool

    Objective-C

    @property BOOL usesFontPanel

    Parameters

    flag

    If flag is YEStrue, the receiver responds to messages from the Font panel and from the Font menu and updates the Font panel with the selection font whenever it changes. If flag is NOfalse the receiver doesn’t do any of these actions.

    Discussion

    By default, an NSText object uses the Font panel and menu.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value that indicates whether the receiver uses the Font panel.

    Declaration

    Swift

    var usesFontPanel: Bool

    Objective-C

    @property BOOL usesFontPanel

    Return Value

    YEStrue if the receiver uses the Font panel, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method shows or hides the ruler, if the receiver is enclosed in a scroll view.

    Declaration

    Swift

    func toggleRuler(_ sender: AnyObject?)

    Objective-C

    - (void)toggleRuler:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • isRulerVisible - isRulerVisible Available in OS X v10.0 through OS X v10.9

    Returns a Boolean value that indicates whether the receiver’s enclosing scroll view shows its ruler.

    Declaration

    Objective-C

    - (BOOL)isRulerVisible

    Return Value

    YEStrue if the receiver’s enclosing scroll view shows its ruler, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Selects the receiver’s characters within aRange.

    Declaration

    Swift

    var selectedRange: NSRange

    Objective-C

    @property NSRange selectedRange

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the range of selected characters.

    Declaration

    Swift

    var selectedRange: NSRange

    Objective-C

    @property NSRange selectedRange

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method selects all of the receiver’s text.

    Declaration

    Swift

    func selectAll(_ sender: AnyObject?)

    Objective-C

    - (void)selectAll:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method copies the selected text onto the general pasteboard, in as many formats as the receiver supports.

    Declaration

    Swift

    func copy(_ sender: AnyObject?)

    Objective-C

    - (void)copy:(id)sender

    Discussion

    A plain text object uses NSStringPboardType for plain text, and a rich text object also uses NSRTFPboardType.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method deletes the selected text and places it onto the general pasteboard, in as many formats as the receiver supports.

    Declaration

    Swift

    func cut(_ sender: AnyObject?)

    Objective-C

    - (void)cut:(id)sender

    Discussion

    A plain text object uses NSStringPboardType for plain text, and a rich text object also uses NSRTFPboardType.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method pastes text from the general pasteboard at the insertion point or over the selection.

    Declaration

    Swift

    func paste(_ sender: AnyObject?)

    Objective-C

    - (void)paste:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method copies the font information for the first character of the selection (or for the insertion point) onto the font pasteboard, as NSFontPboardType.

    Declaration

    Swift

    func copyFont(_ sender: AnyObject?)

    Objective-C

    - (void)copyFont:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method pastes font information from the font pasteboard onto the selected text or insertion point of a rich text object, or over all text of a plain text object.

    Declaration

    Swift

    func pasteFont(_ sender: AnyObject?)

    Objective-C

    - (void)pasteFont:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method copies the paragraph style information for first selected paragraph onto the ruler pasteboard, as NSRulerPboardType, and expands the selection to paragraph boundaries.

    Declaration

    Swift

    func copyRuler(_ sender: AnyObject?)

    Objective-C

    - (void)copyRuler:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method pastes paragraph style information from the ruler pasteboard onto the selected paragraphs of a rich text object.

    Declaration

    Swift

    func pasteRuler(_ sender: AnyObject?)

    Objective-C

    - (void)pasteRuler:(id)sender

    Discussion

    It doesn’t apply to a plain text object.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method deletes the selected text.

    Declaration

    Swift

    func delete(_ sender: AnyObject?)

    Objective-C

    - (void)delete:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – cut:

  • This action method changes the font of the selection for a rich text object, or of all text for a plain text object.

    Declaration

    Swift

    func changeFont(_ sender: AnyObject?)

    Objective-C

    - (void)changeFont:(id)sender

    Discussion

    If the receiver doesn’t use the Font panel, this method does nothing.

    This method changes the font by sending a convertFont: message to the shared NSFontManager and applying each NSFont returned to the appropriate text. See the NSFontManager class specification for more information on font conversion.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the font of all the receiver’s text to aFont.

    Declaration

    Swift

    var font: NSFont?

    Objective-C

    @property(strong) NSFont *font

    Discussion

    This method does not include undo support by default. Clients must invoke shouldChangeTextInRanges:replacementStrings: or shouldChangeTextInRange:replacementString: to include this method in an undoable action.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the font of characters within aRange to aFont.

    Declaration

    Swift

    func setFont(_ font: NSFont, range range: NSRange)

    Objective-C

    - (void)setFont:(NSFont *)font range:(NSRange)range

    Discussion

    This method applies only to a rich text object.

    This method does not include undo support by default. Clients must invoke shouldChangeTextInRanges:replacementStrings: or shouldChangeTextInRange:replacementString: to include this method in an undoable action.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the font of the first character in the receiver’s text, or of the insertion point if there’s no text.

    Declaration

    Swift

    var font: NSFont?

    Objective-C

    @property(strong) NSFont *font

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the alignment of all the receiver’s text to mode.

    Declaration

    Swift

    var alignment: NSTextAlignment

    Objective-C

    @property NSTextAlignment alignment

    Discussion

    The value of mode must be one of the alignments described in NSTextAlignment.

    Text using NSNaturalTextAlignment is actually displayed using one of the other alignments, depending on the natural alignment of the text’s script.

    This method does not include undo support by default. Clients must invoke shouldChangeTextInRanges:replacementStrings: or shouldChangeTextInRange:replacementString: to include this method in an undoable action.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method applies center alignment to selected paragraphs (or all text if the receiver is a plain text object).

    Declaration

    Swift

    func alignCenter(_ sender: AnyObject?)

    Objective-C

    - (void)alignCenter:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method applies left alignment to selected paragraphs (or all text if the receiver is a plain text object).

    Declaration

    Swift

    func alignLeft(_ sender: AnyObject?)

    Objective-C

    - (void)alignLeft:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method applies right alignment to selected paragraphs (or all text if the receiver is a plain text object).

    Declaration

    Swift

    func alignRight(_ sender: AnyObject?)

    Objective-C

    - (void)alignRight:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the alignment of the first paragraph (or all text if the receiver is a plain text object).

    Declaration

    Swift

    var alignment: NSTextAlignment

    Objective-C

    @property NSTextAlignment alignment

    Discussion

    The returned value is one of the alignments described in NSTextAlignment.

    Text using NSNaturalTextAlignment is actually displayed using one of the other alignments, depending on the natural alignment of the text’s script.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the initial writing direction used to determine the actual writing direction for text.

    Declaration

    Swift

    var baseWritingDirection: NSWritingDirection

    Objective-C

    @property NSWritingDirection baseWritingDirection

    Discussion

    The Text system uses this value as a hint for calculating the actual direction for displaying Unicode characters. You should not need to call this method directly. If no writing direction is set, returns NSWritingDirectionNatural.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets the initial writing direction used to determine the actual writing direction for text.

    Declaration

    Swift

    var baseWritingDirection: NSWritingDirection

    Objective-C

    @property NSWritingDirection baseWritingDirection

    Discussion

    If you know the base writing direction of the text you are rendering, you can use this method to specify that direction to the text system.

    This method does not include undo support by default. Clients must invoke shouldChangeTextInRanges:replacementStrings: or shouldChangeTextInRange:replacementString: to include this method in an undoable action.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • This action method applies a superscript attribute to selected text (or all text if the receiver is a plain text object), raising its baseline offset by a predefined amount.

    Declaration

    Swift

    func superscript(_ sender: AnyObject?)

    Objective-C

    - (void)superscript:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method applies a subscript attribute to selected text (or all text if the receiver is a plain text object), lowering its baseline offset by a predefined amount.

    Declaration

    Swift

    func `subscript`(_ sender: AnyObject?)

    Objective-C

    - (void)subscript:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method removes any superscripting or subscripting from selected text (or all text if the receiver is a plain text object).

    Declaration

    Swift

    func unscript(_ sender: AnyObject?)

    Objective-C

    - (void)unscript:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Adds the underline attribute to the selected text attributes if absent; removes the attribute if present.

    Declaration

    Swift

    func underline(_ sender: AnyObject?)

    Objective-C

    - (void)underline:(id)sender

    Discussion

    If there is a selection and the first character of the selected range has any form of underline on it, or if there is no selection and the typing attributes have any form of underline, then underline is removed; otherwise a single simple underline is added.

    Operates on the selected range if the receiver contains rich text. For plain text the range is the entire contents of the receiver.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Attempts to read the RTFD file at path, returning YEStrue if successful and NOfalse if not.

    Declaration

    Swift

    func readRTFDFromFile(_ path: String) -> Bool

    Objective-C

    - (BOOL)readRTFDFromFile:(NSString *)path

    Discussion

    path should be the path for an .rtf file or an .rtfd file wrapper, not for the RTF file within an .rtfd file wrapper.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Writes the receiver’s text as RTF with attachments to a file or directory at path.

    Declaration

    Swift

    func writeRTFDToFile(_ path: String, atomically flag: Bool) -> Bool

    Objective-C

    - (BOOL)writeRTFDToFile:(NSString *)path atomically:(BOOL)flag

    Discussion

    Returns YEStrue on success and NOfalse on failure. If atomicFlag is YEStrue, attempts to write the file safely so that an existing file at path is not overwritten, nor does a new file at path actually get created, unless the write is successful.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSData object that contains an RTFD stream corresponding to the characters and attributes within aRange.

    Declaration

    Swift

    func RTFDFromRange(_ range: NSRange) -> NSData?

    Objective-C

    - (NSData *)RTFDFromRange:(NSRange)range

    Discussion

    Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

    When writing data to the pasteboard, you can use the NSData object as the first argument to NSPasteboard's setData:forType: method, with a second argument of NSRTFDPboardType.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an NSData object that contains an RTF stream corresponding to the characters and attributes within aRange, omitting any attachment characters and attributes.

    Declaration

    Swift

    func RTFFromRange(_ range: NSRange) -> NSData?

    Objective-C

    - (NSData *)RTFFromRange:(NSRange)range

    Discussion

    Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

    When writing data to the pasteboard, you can use the NSData object as the first argument to NSPasteboard's setData:forType: method, with a second argument of NSRTFPboardType.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method searches for a misspelled word in the receiver’s text.

    Declaration

    Swift

    func checkSpelling(_ sender: AnyObject?)

    Objective-C

    - (void)checkSpelling:(id)sender

    Discussion

    The search starts at the end of the selection and continues until it reaches a word suspected of being misspelled or the end of the text. If a word isn’t recognized by the spelling server, a showGuessPanel: message then opens the Guess panel and allows the user to make a correction or add the word to the local dictionary.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method opens the Spelling panel, allowing the user to make a correction during spell checking.

    Declaration

    Swift

    func showGuessPanel(_ sender: AnyObject?)

    Objective-C

    - (void)showGuessPanel:(id)sender

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s maximum size to aSize.

    Declaration

    Swift

    var maxSize: NSSize

    Objective-C

    @property NSSize maxSize

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s maximum size.

    Declaration

    Swift

    var maxSize: NSSize

    Objective-C

    @property NSSize maxSize

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s minimum size to aSize.

    Declaration

    Swift

    var minSize: NSSize

    Objective-C

    @property NSSize minSize

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s minimum size.

    Declaration

    Swift

    var minSize: NSSize

    Objective-C

    @property NSSize minSize

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Controls whether the receiver changes its height to fit the height of its text.

    Declaration

    Swift

    var verticallyResizable: Bool

    Objective-C

    @property(getter=isVerticallyResizable) BOOL verticallyResizable

    Discussion

    If flag is YEStrue it does; if flag is NOfalse it doesn’t.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • isVerticallyResizable - isVerticallyResizable Available in OS X v10.0 through OS X v10.9

    Returns YEStrue if the receiver automatically changes its height to accommodate the height of its text, NOfalse if it doesn’t.

    Declaration

    Objective-C

    - (BOOL)isVerticallyResizable

    Discussion

    By default, an NSText object is vertically resizable.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Controls whether the receiver changes its width to fit the width of its text.

    Declaration

    Swift

    var horizontallyResizable: Bool

    Objective-C

    @property(getter=isHorizontallyResizable) BOOL horizontallyResizable

    Discussion

    If flag is YEStrue it does; if flag is NOfalse it doesn’t.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • isHorizontallyResizable - isHorizontallyResizable Available in OS X v10.0 through OS X v10.9

    Returns YEStrue if the receiver automatically changes its width to accommodate the width of its text, NOfalse if it doesn’t.

    Declaration

    Objective-C

    - (BOOL)isHorizontallyResizable

    Discussion

    By default, an NSText object is not horizontally resizable.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Resizes the receiver to fit its text.

    Declaration

    Swift

    func sizeToFit()

    Objective-C

    - (void)sizeToFit

    Discussion

    The text view will not be sized any smaller than its minimum size, however.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Scrolls the receiver in its enclosing scroll view so the first characters of aRange are visible.

    Declaration

    Swift

    func scrollRangeToVisible(_ range: NSRange)

    Objective-C

    - (void)scrollRangeToVisible:(NSRange)range

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s delegate.

    Declaration

    Swift

    unowned(unsafe) var delegate: NSTextDelegate?

    Objective-C

    @property(assign) id<NSTextDelegate> delegate

    Parameters

    anObject

    The delegate for the receiver.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – delegate

  • Returns the receiver’s delegate.

    Declaration

    Swift

    unowned(unsafe) var delegate: NSTextDelegate?

    Objective-C

    @property(assign) id<NSTextDelegate> delegate

    Return Value

    The receiver’s delegate, or nil if it has none.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • These constants specify text alignment.

    Declaration

    Swift

    enum NSTextAlignment : UInt { case LeftTextAlignment case RightTextAlignment case CenterTextAlignment case JustifiedTextAlignment case NaturalTextAlignment }

    Objective-C

    typedef enum _NSTextAlignment { NSLeftTextAlignment = 0, NSRightTextAlignment = 1, NSCenterTextAlignment = 2, NSJustifiedTextAlignment = 3, NSNaturalTextAlignment = 4 } NSTextAlignment;

    Constants

    • LeftTextAlignment

      NSLeftTextAlignment

      Text is visually left aligned.

      Available in OS X v10.0 and later.

    • RightTextAlignment

      NSRightTextAlignment

      Text is visually right aligned.

      Available in OS X v10.0 and later.

    • CenterTextAlignment

      NSCenterTextAlignment

      Text is visually center aligned.

      Available in OS X v10.0 and later.

    • JustifiedTextAlignment

      NSJustifiedTextAlignment

      Text is justified.

      Available in OS X v10.0 and later.

    • NaturalTextAlignment

      NSNaturalTextAlignment

      Use the natural alignment of the text’s script.

      Available in OS X v10.0 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • These constants specify the writing directions:

    Declaration

    Swift

    enum NSWritingDirection : Int { case Natural case LeftToRight case RightToLeft }

    Objective-C

    enum { NSWritingDirectionNatural = -1, NSWritingDirectionLeftToRight = 0, NSWritingDirectionRightToLeft }; typedef NSInteger NSWritingDirection;

    Constants

    • Natural

      NSWritingDirectionNatural

      The writing direction is determined using the Unicode Bidi Algorithm rules P2 and P3. Default.

      Available in OS X v10.4 and later.

    • LeftToRight

      NSWritingDirectionLeftToRight

      The writing direction is left to right.

      Available in OS X v10.2 and later.

    • RightToLeft

      NSWritingDirectionRightToLeft

      The writing direction is right to left.

      Available in OS X v10.2 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.2 and later.

  • Declaration

    Swift

    var NSTextWritingDirectionEmbedding: Int { get } var NSTextWritingDirectionOverride: Int { get }

    Objective-C

    enum { NSTextWritingDirectionEmbedding = (0 << 1), NSTextWritingDirectionOverride = (1 << 1) };

    Constants

    • NSTextWritingDirectionEmbedding

      NSTextWritingDirectionEmbedding

      Text is embedded in text with another writing direction. For example, an English quotation in the middle of a right-to-left Arabic sentence could be marked as being embedded left-to-right text.

      Available in OS X v10.6 and later.

    • NSTextWritingDirectionOverride

      NSTextWritingDirectionOverride

      Enables character types with inherent directionality to be overridden when required for special cases, such as for part numbers made of mixed English, digits, and Hebrew letters to be written from right to left.

      Available in OS X v10.6 and later.

    Discussion

    You can use the logical OR operator to combine these constants with NSWritingDirectionLeftToRight or NSWritingDirectionRightToLeft when used with NSWritingDirectionAttributeName to specify formatting controls defined by the Unicode Bidirectional Algorithm in Unicode Standard Annex #9.

  • These constants specify the reason for a change of editing focus among text fields, in essence answering the question “why am I leaving the field?”

    Declaration

    Swift

    var NSIllegalTextMovement: Int { get } var NSReturnTextMovement: Int { get } var NSTabTextMovement: Int { get } var NSBacktabTextMovement: Int { get } var NSLeftTextMovement: Int { get } var NSRightTextMovement: Int { get } var NSUpTextMovement: Int { get } var NSDownTextMovement: Int { get } var NSCancelTextMovement: Int { get } var NSOtherTextMovement: Int { get }

    Objective-C

    enum { NSIllegalTextMovement = 0, NSReturnTextMovement = 0x10, NSTabTextMovement = 0x11, NSBacktabTextMovement = 0x12, NSLeftTextMovement = 0x13, NSRightTextMovement = 0x14, NSUpTextMovement = 0x15, NSDownTextMovement = 0x16, NSCancelTextMovement = 0x17, NSOtherTextMovement = 0 };

    Constants

    • NSIllegalTextMovement

      NSIllegalTextMovement

      Currently unused.

      Available in OS X v10.0 and later.

    • NSReturnTextMovement

      NSReturnTextMovement

      The Return key was pressed.

      Available in OS X v10.0 and later.

    • NSTabTextMovement

      NSTabTextMovement

      The Tab key was pressed.

      Available in OS X v10.0 and later.

    • NSBacktabTextMovement

      NSBacktabTextMovement

      The Backtab (Shift-Tab) key was pressed.

      Available in OS X v10.0 and later.

    • NSLeftTextMovement

      NSLeftTextMovement

      The left arrow key was pressed.

      Available in OS X v10.0 and later.

    • NSRightTextMovement

      NSRightTextMovement

      The right arrow key was pressed.

      Available in OS X v10.0 and later.

    • NSUpTextMovement

      NSUpTextMovement

      The up arrow key was pressed.

      Available in OS X v10.0 and later.

    • NSDownTextMovement

      NSDownTextMovement

      The down arrow key was pressed.

      Available in OS X v10.0 and later.

    • NSCancelTextMovement

      NSCancelTextMovement

      The user cancelled the completion.

      Available in OS X v10.3 and later.

    • NSOtherTextMovement

      NSOtherTextMovement

      The user performed some undefined action.

      Available in OS X v10.3 and later.

    Discussion

    They are the possible values for the NSTextMovement key of the NSTextDidEndEditingNotificationuserInfo dictionary. The field editor makes sure that these are the values sent when the user presses the Tab, Backtab, or Return key while editing. The control then uses this information to decide where to send focus next.

  • These constants specify several commonly used Unicode characters.

    Declaration

    Swift

    var NSParagraphSeparatorCharacter: Int { get } var NSLineSeparatorCharacter: Int { get } var NSTabCharacter: Int { get } var NSBackTabCharacter: Int { get } var NSFormFeedCharacter: Int { get } var NSNewlineCharacter: Int { get } var NSCarriageReturnCharacter: Int { get } var NSEnterCharacter: Int { get } var NSBackspaceCharacter: Int { get } var NSDeleteCharacter: Int { get }

    Objective-C

    enum { NSParagraphSeparatorCharacter = 0x2029, NSLineSeparatorCharacter = 0x2028, NSTabCharacter = 0x0009, NSFormFeedCharacter = 0x000c, NSNewlineCharacter = 0x000a, NSCarriageReturnCharacter = 0x000d, NSEnterCharacter = 0x0003, NSBackspaceCharacter = 0x0008, NSBackTabCharacter = 0x0019, NSDeleteCharacter = 0x007f };

    Constants

    • NSParagraphSeparatorCharacter

      NSParagraphSeparatorCharacter

      The paragraph separator character: 0x2029

      Available in OS X v10.0 and later.

    • NSLineSeparatorCharacter

      NSLineSeparatorCharacter

      The line separator character: 0x2028

      Available in OS X v10.0 and later.

    • NSTabCharacter

      NSTabCharacter

      The tab character: 0x0009

      Available in OS X v10.0 and later.

    • NSBackTabCharacter

      NSBackTabCharacter

      The back tab character: 0x0019

      Available in OS X v10.0 and later.

    • NSFormFeedCharacter

      NSFormFeedCharacter

      The form feed character: 0x000c

      Available in OS X v10.0 and later.

    • NSNewlineCharacter

      NSNewlineCharacter

      The newline character: 0x000a

      Available in OS X v10.0 and later.

    • NSCarriageReturnCharacter

      NSCarriageReturnCharacter

      The carriage return character: 0x000d

      Available in OS X v10.0 and later.

    • NSEnterCharacter

      NSEnterCharacter

      The enter character: 0x0003

      Available in OS X v10.0 and later.

    • NSBackspaceCharacter

      NSBackspaceCharacter

      The backspace character: 0x0008

      Available in OS X v10.0 and later.

    • NSDeleteCharacter

      NSDeleteCharacter

      The delete character: 0x007f

      Available in OS X v10.0 and later.

  • Posted when an NSText object begins any operation that changes characters or formatting attributes.

    The notification object is the notifying NSText object. This notification does not contain a userInfo dictionary.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted after an NSText object performs any operation that changes characters or formatting attributes.

    The notification object is the notifying NSText object. This notification does not contain a userInfo dictionary.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted when focus leaves an NSText object, whether or not any operation has changed characters or formatting attributes.

    The notification object is the notifying NSText object. The userInfo dictionary contains the following information:

    Key

    Value

    @"NSTextMovement"

    Possible movement code values are described in Movement Codes.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.