A set of optional methods that text view delegates can use to manage selection, set text attributes, work with the spell checker, and more.


protocol NSTextViewDelegate


Accessing Text System Objects

func undoManager(for: NSTextView) -> UndoManager?

Returns the undo manager for the specified text view.

Controlling Display

Supporting Quick Look

func textView(NSTextView, urlForContentsOf: NSTextAttachment, at: Int) -> URL?

Returns a URL representing the document contents for a text attachment.

Managing the Pasteboard

Setting Text Attributes

func textView(NSTextView, shouldChangeTextIn: NSRange, replacementString: String?) -> Bool

Sent when a text view needs to determine if text in a specified range should be changed.

func textView(NSTextView, shouldChangeTextInRanges: [NSValue], replacementStrings: [String]?) -> Bool

Sent when a text view needs to determine if text in an array of specified ranges should be changed.

func textViewDidChangeTypingAttributes(Notification)

Sent when a text view’s typing attributes change.

Control Sharing Service Picker

Performing Commands

func textView(NSTextView, doCommandBy: Selector) -> Bool

Sent to allow the delegate to perform the command for the text view.

Contextual Menu Management

func textView(NSTextView, menu: NSMenu, for: NSEvent, at: Int) -> NSMenu?

Allows delegate to control the context menu returned by the text view.


Inherits From

See Also

Text Views

class NSTextField

Text that the user can select or edit and that sends its action message to its target when the user presses the Return key.

protocol NSTextFieldDelegate

A protocol that a text field delegate can use to control its field editor action menu.

class NSTextView

A view that draws text and handles user interactions with that text.

protocol NSTextDelegate

A set of optional methods implemented by the delegate of an NSText object to edit text and change text formats.

class NSText

The most general programmatic interface for objects that manage text.