Skip to content

Commit

Permalink
chore: Lint issues in Examples (#222)
Browse files Browse the repository at this point in the history
* fix examples lint issues

* fix lint issues in InstantSearch

* run tests and linter on pull request
  • Loading branch information
VladislavFitz authored May 22, 2022
1 parent a4fb97e commit 7d0066c
Show file tree
Hide file tree
Showing 214 changed files with 1,551 additions and 1,727 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Swift

on: [push]
on: [push, pull_request]

jobs:
test:
Expand Down
2 changes: 0 additions & 2 deletions Examples/CategoriesHits/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import InstantSearch
import UIKit

extension CategoriesHits {

class SearchResultsController: UITableViewController {

var didSelectSuggestion: ((String) -> Void)?

enum Section: Int, CaseIterable {
case categories
case hits

var title: String {
switch self {
case .categories:
Expand All @@ -27,7 +27,7 @@ extension CategoriesHits {
return "Products"
}
}

var cellReuseIdentifier: String {
switch self {
case .categories:
Expand All @@ -36,15 +36,15 @@ extension CategoriesHits {
return "hits"
}
}

init?(section: Int) {
self.init(rawValue: section)
}

init?(indexPath: IndexPath) {
self.init(section: indexPath.section)
}

}

weak var categoriesInteractor: FacetListInteractor? {
Expand All @@ -56,7 +56,7 @@ extension CategoriesHits {
}.onQueue(.main)
}
}

weak var hitsInteractor: HitsInteractor<Hit<Product>>? {
didSet {
oldValue?.onResultsUpdated.cancelSubscription(for: tableView)
Expand All @@ -66,17 +66,17 @@ extension CategoriesHits {
}.onQueue(.main)
}
}

override func viewDidLoad() {
super.viewDidLoad()
tableView.register(CategoryTableViewCell.self, forCellReuseIdentifier: Section.categories.cellReuseIdentifier)
tableView.register(ProductTableViewCell.self, forCellReuseIdentifier: Section.hits.cellReuseIdentifier)
}

override func numberOfSections(in tableView: UITableView) -> Int {
return Section.allCases.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let section = Section(rawValue: section) else { return 0 }
switch section {
Expand All @@ -86,12 +86,12 @@ extension CategoriesHits {
return hitsInteractor?.numberOfHits() ?? 0
}
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let section = Section(rawValue: indexPath.section) else { return UITableViewCell() }

let cell: UITableViewCell

switch section {
case .categories:
cell = tableView.dequeueReusableCell(withIdentifier: Section.categories.cellReuseIdentifier, for: indexPath)
Expand All @@ -108,10 +108,10 @@ extension CategoriesHits {
productTableViewCell.setup(with: hit)
}
}

return cell
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
guard let section = Section(rawValue: section) else { return nil }
switch section {
Expand All @@ -123,7 +123,7 @@ extension CategoriesHits {
return section.title
}
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
guard let section = Section(indexPath: indexPath) else { return 0 }
switch section {
Expand All @@ -133,7 +133,7 @@ extension CategoriesHits {
return 100
}
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let section = Section(rawValue: indexPath.section) else { return }
switch section {
Expand All @@ -148,5 +148,5 @@ extension CategoriesHits {
}

}

}
30 changes: 15 additions & 15 deletions Examples/CategoriesHits/CategoriesHits.SearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import UIKit
import InstantSearch

enum CategoriesHits {

class SearchViewController: UIViewController {

let searchController: UISearchController

let searchBoxConnector: SearchBoxConnector
let textFieldController: TextFieldController

let searcher: MultiSearcher
let categoriesInteractor: FacetListInteractor
let hitsInteractor: HitsInteractor<Hit<Product>>

let searchResultsController: SearchResultsController

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
searcher = .init(client: .instantSearch)
searchResultsController = .init(style: .plain)
Expand All @@ -35,33 +35,33 @@ enum CategoriesHits {
controller: textFieldController)
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()

configureUI()

let facetsSearcher = searcher.addFacetsSearcher(indexName: .instantSearch,
attribute: "categories")
categoriesInteractor.connectFacetSearcher(facetsSearcher)
searchResultsController.categoriesInteractor = categoriesInteractor

let hitsSearchers = searcher.addHitsSearcher(indexName: .instantSearch)
hitsInteractor.connectSearcher(hitsSearchers)
searchResultsController.hitsInteractor = hitsInteractor

searcher.search()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
searchController.isActive = true
}

func configureUI() {
title = "Categories & Hits"
view.backgroundColor = .white
Expand All @@ -71,7 +71,7 @@ enum CategoriesHits {
searchController.automaticallyShowsCancelButton = false
navigationItem.searchController = searchController
}

}

}
2 changes: 0 additions & 2 deletions Examples/CategoriesHits/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?


func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
setMain(CategoriesHits.SearchViewController(), for: scene)
}

}

4 changes: 0 additions & 4 deletions Examples/Examples/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
Expand All @@ -31,6 +29,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


}

12 changes: 6 additions & 6 deletions Examples/Examples/Demo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import UIKit
import AlgoliaSearchClient

protocol DemoProtocol {

var objectID: ObjectID { get }
var name: String { get }
var type: String { get }

}

}

struct Demo: Codable, DemoProtocol {

let objectID: ObjectID
let name: String
let type: String


// swiftlint:disable type_name
enum ID: String {
case showcaseImperative = "showcase_imperative_ui"
case showCaseDeclarative = "showcase_declarative_ui"
Expand All @@ -38,5 +38,5 @@ struct Demo: Codable, DemoProtocol {
case codexMultipleIndex = "codex_multiple_index"
case codexCategoriesHits = "codex_categories_hits"
}

}
32 changes: 16 additions & 16 deletions Examples/Examples/DemoListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import UIKit
import InstantSearch

final class DemoListViewController<Demo: DemoProtocol & Codable>: UITableViewController {

let searcher: HitsSearcher
let filterState: FilterState
let hitsInteractor: HitsInteractor<Demo>
let textFieldController: TextFieldController
let searchBoxInteractor: SearchBoxInteractor

var didSelect: ((Demo) -> Void)?

let searchController: UISearchController
private let cellIdentifier = "cellID"
var groupedDemos: [(groupName: String, demos: [Demo])]
Expand All @@ -29,7 +29,7 @@ final class DemoListViewController<Demo: DemoProtocol & Codable>: UITableViewCon
filterState = .init()
hitsInteractor = HitsInteractor(infiniteScrolling: .on(withOffset: 10), showItemsOnEmptyQuery: true)
groupedDemos = []

searcher.request.query.hitsPerPage = 40
searcher.connectFilterState(filterState)
hitsInteractor.connectSearcher(searcher)
Expand All @@ -49,50 +49,50 @@ final class DemoListViewController<Demo: DemoProtocol & Codable>: UITableViewCon
viewController.updateDemos(demos)
}
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground
searcher.search()
}

func updateDemos(_ demos: [Demo]) {
let demosPerType = Dictionary(grouping: demos, by: { $0.type })
self.groupedDemos = demosPerType
.sorted { $0.key < $1.key }
.map { ($0.key, $0.value.sorted { $0.name < $1.name } ) }
.map { ($0.key, $0.value.sorted { $0.name < $1.name }) }
DispatchQueue.main.async {
self.tableView.reloadData()
}
}

//MARK: UITableViewDataSource
// MARK: UITableViewDataSource

override func numberOfSections(in tableView: UITableView) -> Int {
return groupedDemos.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return groupedDemos[section].demos.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let demo = groupedDemos[indexPath.section].demos[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
cell.textLabel?.text = demo.name
return cell
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return groupedDemos[section].groupName
}
//MARK: UITableViewDelegate

// MARK: UITableViewDelegate

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let demo = groupedDemos[indexPath.section].demos[indexPath.row]
didSelect?(demo)
Expand Down
Loading

0 comments on commit 7d0066c

Please sign in to comment.