Search criteria in a search text field, represented by text and an optional icon.


class UISearchToken : NSObject


Use search tokens to help users understand and edit complex search queries in a UISearchTextField. A token acts like a single character in standard text interactions such as deleting, selecting, or dragging. A search token should always have text and may also have an icon.

Screenshot of a search window with a red circle and the words "Red Flowers Carnation". The red dot and "Red Flowers" are in a gray box labeled as a UISearchToken and "Carnation" is labeled as text.

Assign a representedObject to each search token that's meaningful to your app. By attaching this extra data to the token you can reconstruct the full search query using information available in the search field when, for example, your app starts from state restoration or the user starts a search.


Creating a Search Token

init(icon: UIImage?, text: String)

Creates a search token with the specified text and icon (if any).

var representedObject: Any?

The object represented by the search token.


Inherits From

Conforms To

See Also

Text Views

class UILabel

A view that displays one or more lines of informational text.

class UITextField

An object that displays an editable text area in your interface.

class UITextView

A scrollable, multiline text region.

class UISearchTextField

A view for displaying and editing text and search tokens.

protocol UISearchTextFieldDelegate

A method that supports cutting, copying, and dragging tokens from a search field.

Drag and Drop Customization

Extend the standard drag and drop support for text views to include custom types of content.