Post

Replies

Boosts

Views

Activity

Reply to Searching in Categories array
Thank you for your answer. After changes in codes the result looks the same. To make it more clear I have tableView which include array with structs. Typing in search bar still filter me just name of Category with all Sign positions, instead of searched Sign what is my point. class Sign {     let code: String     let name: String     let description: String     let picture: String          init(code: String, name: String, description: String, picture: String) {         self.code = code         self.name = name         self.description = description         self.picture = picture     } } class Category {     let name: String     let sign: [Sign]          init(name: String, sign: [Sign]) {         self.name = name         self.sign = sign     } } Looking for showing name from Sign in my table after typing in search bar. I think your code is closer but still append category. Eg. var categories: [Category] = [         Category(name: "X", sign: [Sign(code: "X-1", name: "***"), Category(name: "Y", sign: [Sign(code: "Y-1", name: "Yyy"), After typing "yy" || "y" in search bar I need my tableView shows only Sign which contains "yy".
Nov ’22
Reply to Searching in Categories array
My current TableView configuration: override func numberOfSections(in tableView: UITableView) -> Int {                  return filteredCategories.count              }     override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {                  return filteredCategories[section].sign.count     }          override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {         switch section {         case 0:             return filteredCategories[0].name         case 1:             return filteredCategories[1].name         case 2:             return filteredCategories[2].name         case 3:             return filteredCategories[3].name         default:             return "Error"         }     }          override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {                  let cell = tableView.dequeueReusableCell(withIdentifier: PropertyKeys.categorieCell, for: indexPath) as! SignTableViewCell                  let categorie = filteredCategories[indexPath.section]         let sign = categorie.sign[indexPath.row]         cell.signImagemin.image = UIImage(named: sign.picture)         cell.signCodeMin.text = sign.code         cell.signDescriptionMin.text = sign.name                  return cell     }
Dec ’22
Reply to Searching in Categories array
Still tableView shows result of this class: class Category {     let name: String     var sign: [Sign]          init(name: String, sign: [Sign]) {         self.name = name         self.sign = sign     } } instead of this one: class Sign {     let code: String     let name: String          init(code: String, name: String) {         self.code = code         self.name = name     } }
Dec ’22
Reply to Searching in Categories array
I solved the problem with searching, but now my tableView doesn't back to the original content. I see results but, when searchbar is empty I see original content + filtered. I can't figure out how to link searching with the filteredCategories and avoid touching to the original one. func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {                  let searchText = searchText.lowercased()                  if searchText == "" {             filteredCategories = categories         } else {             for categorie in categories {                 if categorie.sign.filter({$0.name.contains(searchText)}).count != 0 {                     let signs = categorie.sign.filter() { $0.name.contains(searchText.lowercased()) }                     let newCat = categorie                     newCat.sign = signs                     filteredCategories.append(newCat)                 }             }         }                  self.tableView.reloadData()     }
Dec ’22
Reply to Picking random array elements for button
We have it, thank you very much. Sorry if my questions are not fully detailed, but after months of coding practice now I want to learn how to improve it. I've used first way, which fit perfect to the goal and project, optionals stayed with variables to avoid build problems at the beginning, I will improve it at the final stage. I've used this way in IBAction button to check if answer is correct:  if sender.titleLabel?.text == firstSign.name {
Dec ’22