About this widget
Each search results comes with aSearchStats
structure containing metadata that you might display in your search experience.
The following information is available within SearchStats
:
hitsPerPage
. Number of hits per page.totalHitsCount
. Total number of hits.pagesCount
. Total number of pages.page
. Current page.processingTimeMS
. Processing time of the request (in ms).query
. Query text that produced these results.
StatsController
:
LabelStatsController
. Presents metadata inUILabel
in the form of text.AttributedLabelStatsController
. Presents metadata inUILabel
in the form of attributed text.
StatsController
is defined in the presenter closure provided while connecting the controller with Interactor
.
Examples
Instantiate aStatsConnector
and launch an initial search on its Searcher
.
Swift
Parameters
The logic applied to Stats.
The Controller interfacing with a concrete stats view.
The Presenter defining how stats appear in the controller.
Low-level API
If you want to fully control theStats
components and connect them manually, you can use the following components:
Searcher
. TheSearcher
that handles your searches.StatsInteractor
. The logic applied to the stats.StatsController
. The controller that interfaces with a concrete stats view.
Swift
Customizing your view
The default controllers, such as theLabelStatsController
,
work well when you want to use native UIKit with their default behavior.
If you want to use another component (other than a UILabel
) such as a UITextView
,
a third-party view,
or want to introduce some custom behavior to the already provided UIKit component,
you can create your own controller conforming to the StatsTextController
protocol.
Protocol
func setItem(_ item: String?)
:
Function called when new metadata are received.
Example
Swift
SwiftUI
InstantSearch provides theStatsTextObservableController
data model,
which is an implementation of the StatsTextController
protocol adapted for usage with SwiftUI.
StatsTextObservableController
must be connected to the StatsConnector
or StatsConnector
like any other StatsTextController
implementation.
The example of the current filters view presenting the grouped filters.
Swift
StatsTextObservableController
as a data model.
It provides the stats
property to streamline the design process of your custom SwiftUI view.