Skip to main content
Signature

Explore example code

Browse the Filter Toggle example code on GitHub.

About this widget

Filter Toggle is a filtering component that displays any kind of filter, and lets users refine the search results by toggling it on or off.

Examples

Instantiate a FilterToggleConnector and launch an initial search on its Searcher.
Swift

Parameters

FilterState
required
The FilterState that holds your filters.
Filter
required
The Filter to toggle.
SelectableInteractor<Filter>
required
default: .init()
The logic applied to Filter Toggle.
Bool
required
Whether the filter is initially selected.
RefinementOperator
default: .and
Whether the filter is added to a conjuncitve(and) or a disjuncitve (or) group in the filter state.
String
default: nil
Defines the group name in which filter will be placed in FilterState. If not specified, the name of the filter attribute will be used as a group name.
CurrentFiltersController
default: nil
The Controller interfacing with a concrete toggle filter view.

Low-level API

If you want to fully control the Filter Toggle components and connect them manually, use the following components:
Swift

Customizing your view

The default controllers, such as FilterSwitchController, work well when you want to use native UIKit with their default behavior. If you want to use another component such as a UIButton, a third-party input view, or you want to introduce some custom behavior to the already provided UIKit component, you can create your own controller conforming to the SelectableController protocol.

Protocol

var onClick: ((Bool) -> Void)?: Closure to call when a filter is toggled. func setSelected(_ isSelected: Bool) Function called when a selection state of filter is updated. This is the UI State of the toggle. Make sure to update your view here when you get the new selection state.

Example

Swift

SwiftUI

InstantSearch provides the FilterToggleObservableController data model, which is an implementation of the SelectableController protocol adapted for usage with SwiftUI. FilterToggleObservableController must be connected to the FilterToggleConnector or SelectableInteractor<Filter> like any other SelectableController implementation. The example of the toggle filter view using the Toggle component provided by SwiftUI.
Swift
If you prefer to create a custom filter toggle SwiftUI view, you can directly use the FilterToggleObservableController as a data model. It provides filter and isSelected properties to streamline the design process of your custom SwiftUI view.
Last modified on July 22, 2026