API Reference
/
iOS InstantSearch Widgets
/
Filter Toggle
Apr. 24, 2019
Filter Toggle
About this widget
Filter Toggle is a filtering view that displays any kind of filter, and lets the user refine the search results by toggling it on or off.
To add a filter toggle to your search experience, use these components:
Searcher
: TheSearcher
that handles your searches.FilterState
: The current state of the filters.SelectableInteractor
: The logic applied to the filter.SelectableController
: The controller that interfaces with a concrete toggle view.
Examples
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class ToggleFilterViewController: UIViewController {
let searcher: SingleIndexSearcher = .init(appID: "YourApplicationID",
apiKey: "YourSearchOnlyAPIKey",
indexName: "YourIndexName")
let filterState: FilterState = .init()
let filter: Filter.Tag = "on sale"
lazy var onSaleFilterInteractor: SelectableInteractor<Filter.Tag> = { return .init(item: filter) }()
let onSaleSwitchController: FilterSwitchController<Filter.Tag> = .init(switch: UISwitch())
override func viewDidLoad() {
super.viewDidLoad()
setup()
}
func setup() {
searcher.connectFilterState(filterState)
onSaleFilterInteractor.connectFilterState(filterState)
onSaleFilterInteractor.connectController(onSaleSwitchController)
}
}
Parameters
filter
|
type: Filter
Required
The filter to apply. |
||
Copy
|
|||
operator
|
type: RefinementOperator
default: .or
Optional
Defines the group type in which filter will be placed in |
||
Copy
|
|||
groupName
|
type: String?
default: nil
Optional
Defines the group name in which filter will be placed in |
||
Copy
|
|||
isSelected
|
type: Boolean
default: false
Optional
If |
||
Copy
|