Mac Developer Library

Developer

AppKit Framework Reference NSSearchField Class Reference

Options
Deployment Target:

On This Page
Language:

NSSearchField

An NSSearchField object implements a text field control that is optimized for performing text-based searches. The control 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 though to manipulate some aspects of the search field. For additional information about search fields and how to manipulate them, see the NSSearchFieldCell class.

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

    Declaration

    Swift

    var searchMenuTemplate: NSMenu?

    Objective-C

    @property(strong) NSMenu *searchMenuTemplate

    Availability

    Available in OS X v10.10 and later.

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

    Declaration

    Swift

    var sendsSearchStringImmediately: Bool

    Objective-C

    @property BOOL sendsSearchStringImmediately

    Discussion

    When the value of this property is YES, the field calls its action method immediately upon notification of any changes to the search field. When the value is NO, the field pauses briefly after receiving a notification and then calls its action method. Pausing gives the user an opportunity to type more text into the search field and minimize the number of searches that are performed.

    Availability

    Available in OS X v10.10 and later.

  • 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.

    Declaration

    Swift

    var sendsWholeSearchString: Bool

    Objective-C

    @property BOOL sendsWholeSearchString

    Discussion

    When the value of this property is yes, the field calls its action method when the user clicks the search button or presses Return. When the value is NO, the field calls the action method after each keystroke. The default value of this property is no.

    Availability

    Available in OS X v10.10 and later.

  • The list of recent search strings for the control.

    Declaration

    Swift

    var recentSearches: [String]

    Objective-C

    @property(copy) NSArray <NSString *> *recentSearches

    Discussion

    An array of NSString objects, each of which contains a search string either displayed in the search menu or from a recent autosave archive. If there have been no recent searches and no prior searches saved under an autosave name, this array may be empty.

    Availability

    Available in OS X v10.3 and later.

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

    Declaration

    Swift

    var maximumRecents: Int

    Objective-C

    @property NSInteger maximumRecents

    Discussion

    The value of this property must be between 0 and 254. Specifying a negative value for the property sets it to the default value, which is 10. Specifying a value greater than 254 sets the property to 254.

    When the maximum number of search strings is exceeded, the oldest search string on the menu is dropped.

    Availability

    Available in OS X v10.10 and later.

  • The autosave name under which the receiver automatically archives the list of recent search strings

    Declaration

    Swift

    var recentsAutosaveName: String?

    Objective-C

    @property(copy) NSString *recentsAutosaveName

    Discussion

    Used as a key in the standard user defaults to save the recent searches. If you specify nil or an empty string for this property, no autosave name is set and searches are not autosaved.

    Availability

    Available in OS X v10.3 and later.