A text field control that’s optimized for performing text-based searches.


class NSSearchField : NSTextField


NSSearchField provides a customized text field for entering search data, a search button, a cancel button, and a pop-up icon menu for listing recent search strings and custom search categories.

An NSSearchField object wraps an NSSearchFieldCell object. Access to most search field attributes occurs through the cell, which provides a more comprehensive programmatic interface for manipulating the search field. You can use an NSSearchField object to manipulate some aspects of the search field.

For additional information about search fields and how to manipulate them, see the NSSearchFieldCell class.


Managing Search

var delegate: NSSearchFieldDelegate?

The delegate for the search field, or nil if the search field doesn’t have a delegate.

protocol NSSearchFieldDelegate

A protocol that a search field delegate can use to determine when a search started or ended.

Managing Menu Templates

var searchMenuTemplate: NSMenu?

The menu object used to dynamically construct the search field’s pop-up icon menu.

class let clearRecentsMenuItemTag: Int

The menu item for clearing the current set of recent string searches in the menu.

class let noRecentsMenuItemTag: Int

The menu item that describes a lack of recent search strings.

class let recentsMenuItemTag: Int

The location of recent search strings in the “recents” menu group.

class let recentsTitleMenuItemTag: Int

The menu item that provides the title of the menu group for recent search strings.

Managing Search Modes

var sendsSearchStringImmediately: Bool

A Boolean value indicating whether the cell calls its action method immediately when an appropriate action occurs.

var sendsWholeSearchString: Bool

A Boolean value indicating whether the cell calls its search action method when the user clicks the search button or presses Return, or after each keystroke.

Managing Recent Searches

var recentSearches: [String]

The list of recent search strings for the control.

var maximumRecents: Int

The maximum number of search strings that can appear in the search menu.

var recentsAutosaveName: NSSearchField.RecentsAutosaveName?

The name under which the search field automatically archives the list of recent search strings.

typealias NSSearchField.RecentsAutosaveName

The string that stores the name under which a search field automatically archives it’s list of recent search strings.

Configuring the Search Field

var centersPlaceholder: Bool

A Boolean value that determines whether the search field’s components are centered within the control.

Getting Search Field Metrics

func rectForCancelButton(whenCentered: Bool) -> NSRect

The rectangle for the cancel button within the bounds of the search field.

func rectForSearchButton(whenCentered: Bool) -> NSRect

The rectangle for the search button within the bounds of the search field.

func rectForSearchText(whenCentered: Bool) -> NSRect

The rectangle for the search text within the bounds of the field.