ios - Type 'NSPredicate has no subscript members' -


i trying implement search call results database. manage database print in console not access via search.

here code use :

import uikit  class searchtableviewcontroller: uitableviewcontroller, uisearchresultsupdating {  var searchpredicate = nspredicate() var filteredappleproducts = [string]() var resultsearchcontroller = uisearchcontroller!() var arrdataarticles: nsmutablearray!  override func viewdidload() {     super.viewdidload()      self.searchpredicate = nspredicate(format: "self like[c] %@", resultsearchcontroller.searchbar.text!)      self.resultsearchcontroller = uisearchcontroller(searchresultscontroller: nil)     self.resultsearchcontroller.searchresultsupdater = self      self.resultsearchcontroller.dimsbackgroundduringpresentation = false     self.resultsearchcontroller.searchbar.sizetofit()      self.tableview.tableheaderview = self.resultsearchcontroller.searchbar      self.tableview.reloaddata()     self.getallarticles() }  func getallarticles() {     arrdataarticles = nsmutablearray()     arrdataarticles = modelbd.getinstance().getallarticles() }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  // mark: - table view data source  override func numberofsectionsintableview(tableview: uitableview) -> int {     // #warning incomplete implementation, return number of sections     return 1 }  override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {      if self.resultsearchcontroller.active {         return self.filteredappleproducts.count     }     else {         return 0     } }  override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath) uitableviewcell?      if self.resultsearchcontroller.active {         cell!.textlabel?.text = self.filteredappleproducts[indexpath.row]     }     else {         cell!.textlabel?.text = self.searchpredicate[indexpath.row] as! string     }      return cell! }  func updatesearchresultsforsearchcontroller(searchcontroller: uisearchcontroller) {     self.filteredappleproducts.removeall(keepcapacity: false)      let searchpredicate = nspredicate(format: "self contains[c] %@", searchcontroller.searchbar.text!)      let array = (self.appleproducts nsarray).filteredarrayusingpredicate(searchpredicate)      self.filteredappleproducts = array as! [string]      self.tableview.reloaddata() }   } 

type 'nspredicate has no subscript members'

error appears on lines

cell!.textlabel?.text = self.searchpredicate[indexpath.row] as! string 

and

let array = (self.appleproducts nsarray).filteredarrayusingpredicate(searchpredicate) 

anyone knows how fix this?

thanks in advance time.

you cannot use instance member in constant this. in predicate suppose existence of resultsearchcontroller. instead initialize predicate in viewdidload() or during class initialization.

e.g.:

var searchpredicate: nspredicate?  override func viewdidload() {     super.viewdidload()     self.searchpredicate = nspredicate(format: "self like[c] %@", resultsearchcontroller.searchbar.text!)  [...] 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -