Code Monkey home page Code Monkey logo

Comments (4)

VladislavFitz avatar VladislavFitz commented on May 13, 2024 1

Hello @rayfarer ,

Thank you for your feedback. You are right, the Getting Started guide is not up-to-date at the moment.
We are about to release a significant update for InstantSearch with lots of new helpers and the Guide will be updated accordingly.

Stay tuned!

from instantsearch-ios.

VladislavFitz avatar VladislavFitz commented on May 13, 2024 1

Hi @rayfarer,
Well done, this is exactly what we expect from developers as HitsController protocol implementation 🙂
We sunset HitsTableController implementation because it required the inheritance for customization. The protocol-based approach is just a bit more complicated, but is way more flexible. That's why we encourage developers to use it within long-term projects. But we might provide more implementation guides for sure.
By the way, we have a repository containing the examples of search features implementations using InstantSearch. You can take a look at it to get inspiration for your own projects.

from instantsearch-ios.

rayfarer avatar rayfarer commented on May 13, 2024

I see that these were marked as "Obsolete old table/collection view helpers." I guess it would just be helpful if the Getting Start guide was updated, because it still uses these obsolete components.

from instantsearch-ios.

rayfarer avatar rayfarer commented on May 13, 2024

I'm happy to hear the guide will be updated soon. I guess I'm just a little discouraged because the obsolete HitsTableController is now preventing my app from building. Do you have any suggestions to work around this?

Edit

After a little thought, I implemented my own Table Controller like the hint suggested, using the Demos as my guide. Still working out the kinks, but I think this is a better solution than in v5. Thanks again for all your work. If I can help with the documentation, I'd be happy to.

Here's what I did:

  1. Created a file called ResultsTableViewController.swift. Made sure it conformed to the HitsController protocol.
  2. Declared a table controller according to the user guides:

let hitsTableController = ResultsTableViewController()

Example ResultsTableViewController.swift

import Foundation
import InstantSearch
import UIKit

class ResultsTableViewController: UITableViewController, HitsController {
  
	var hitsSource: HitsInteractor<Hit>?
	
	let cellID = "collectioncell"
	
	override func viewDidLoad() {
	  super.viewDidLoad()
	  tableView.register(CollectionCell.self, forCellReuseIdentifier: cellID)
	}
	
	override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
	  return hitsSource?.numberOfHits() ?? 0
	}
	
	override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
	  guard let cell = tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath) as? CollectionCell else {
		return .init()
	  }
				  // Get hit data and assign it to stuff in your cell
				  let hit = hitsSource?.hit(atIndex: indexPath.row)
				  let artist = hit?.artist
                                   let year = hit?.year
	  return cell
	}
	
	override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
		  
		// If you select a hit, logic to handle that goes here.
		
		 let hit = hitsSource?.hit(atIndex: indexPath.row)
			   
			 
		
	}
	
	override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
	  // Controls height of hit cell
        return 120

	}

}

from instantsearch-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.