iOS App Two Separate Indices in Two Separate View Controllers



Following the InstantSearch iOS docs, I have been trying to create two view controllers that show two different indices.


View Controller A shows Index A
View Controller B shows Index B

My App Delegate code:

let ALGOLIA_APP_ID = "exampleID"
let ALGOLIA_API_KEY = "***"

let searcherIds = [SearcherId(index: "indexA"), SearcherId(index: "indexB")]
InstantSearch.shared.configure(appID: ALGOLIA_APP_ID, apiKey: ALGOLIA_API_KEY, searcherIds: searcherIds)

I am able to display Index A in View Controller A using the MultiHitsTableViewController described in the latter half of this guide. I have my outlets set up correctly, everything pointing to the right place, and my VC viewDidLoad looks like this:

hitsTableView = tableView
tableView.indices = "indexA"
InstantSearch.shared.registerAllWidgets(in: self.view)

However, when I do the same thing in View Controller B, using this:

hitsTableView = tableView
tableView.indices = "indexB"
InstantSearch.shared.registerAllWidgets(in: self.view)

I get a fatal error: “When using multi-indexing, All output widgets have to target a specific index”

Now, I believe I did target a specific index, but no matter what I try, I simply cannot get my View Controller B to display Index B, or any index for that matter. The error seems to be occurring when I call at the “InstantSearch.shared.registerAllWidgets(in: self.view)” line.

It has been frustratingly difficult to do something as simple as display two indices within my app. It seems to be set up to display only one index. I do not want two indices in the same view controller, I want two separate view controllers displaying unique indices.

Please let me know if I am doing something wrong, because I really had hoped to be able to use Algolia for my iOS app.

P.S. I know there was a similar post to this one but it did not really answer the person’s question. It just pointed to an example where multiple indices were displayed on one table view controller.