Searchbar filtering issue

前端 未结 3 1592
梦毁少年i
梦毁少年i 2021-01-16 10:13

Im new to the swift, I am trying to filter name from an array using the search bar in console am getting what I entered in the search bar but filtering with predicate im not

3条回答
  •  余生分开走
    2021-01-16 10:48

    let array = self.caseListOfBooker.filter{$0.person_of_interest.contains(searchString)}
    

    You are getting array of CaseDetails objects and trying to cast to array of String

    It fails. You need to get string values from the CaseDetails object and join them

    Use

    filteredString = array.map { $0.person_of_interest }
    

    Or

    for caseDetail in array {
        filteredString.append(caseDetail.person_of_interest)
    }
    

    Instead of

    if let list = array as? [String]{
        filteredString=list
    }
    

提交回复
热议问题