How to search in TableView by Section and Row?


#1

How to search in TableView by Section and Row ?

Get nested JSON from the site.

self.partnerBranchs = try decoder.decode([PartnerBranch].self, from: data)

Model:

struct PartnerBranch: Decodable {
let id: Int?
let address: String?
let contacts: String?
let name: String?
let logo: String?
let stocks: [Stock]
}

struct Stock: Decodable {
let id: Int?
let title: String?
let description: String?
let images: String?
}

PartnerBranch is a section
Stock is a row

How do I search for both?

Now works only on sections:

func filterContentForSearchText(_ searchText: String) {
partnerBranchsFiltered = partnerBranchs.filter({ (partnerBranch: PartnerBranch) -> Bool in
return partnerBranch.name!lowercased().contains(searchText.lowercased()
})

As I understand it I have to somehow use compactMat for stocks.

Sorry for my English. Thank you in advance.


(Quinn “The Eskimo!”) #2

It depends on what you want the results to look like. AFAICT there are two criteria here:

  • Does the branch name contain searchText? (A)

  • Does the branch include any stock items that contain searchText? (B)

Do you want the branch to be included in the list if A is true but B is false?

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple