swift - How to customise the search feature in UITablView -


in search bar result want comparison using anchoredsearch option first , if don't value in want comparison using caseinsensitivesearch option only.

i have attached code below searchbar.

func searchbar(searchbar: uisearchbar, textdidchange searchtext: string) {          self.array = self.getuniqarraydata(self.array)         filteredtabledata = array.filter({ (text) -> bool in             let tmp: nsstring = text             var range = tmp.rangeofstring(searchtext, options: (nsstringcompareoptions.anchoredsearch | nsstringcompareoptions.caseinsensitivesearch ))              return range.location != nsnotfound         })          if(searchtext == ""){              searchactive = false;         } else {             searchactive = true;         }         self.xyztable.reloaddata()     } 

please let me know how can filter using anchoredsearch first , if don't find in search using caseinsensitivesearch option.

any example or sample code or links helpful

it's straightforward sequencing. i've cleaned few things; tmp unnecessary.

// don't think intend overwrite underlying data because // user did search. did mean local variable: let uniqarray = self.getuniqarraydata(self.array) let tryanchored = uniqarray.filter { (text) -> bool in     var range = text.rangeofstring(searchtext, options: .anchoredsearch)     return range.location != nsnotfound } if tryanchored.count > 0 {     self.filteredtabledata = tryanchored } else {     // maybe have local 'let' here too, , if 1 comes     // empty, don't reload table data @ all?     self.filteredtabledata = uniqarray.filter { (text) -> bool in         var range = text.rangeofstring(searchtext, options: .caseinsensitivesearch)         return range.location != nsnotfound     } } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -