swift - Why is rangeOfString returning a value instead of NSNotFound? -
in screenshot above can see rangeofstring
has returned location "dent" in string "why #thisisacoup trending? - bbc news"
i expect have returned nsnotfound
instead since "dent" not substring of string in tmp
variable. can explain me why is?
here's code used in screenshot.
func searchbar(searchbar: uisearchbar, textdidchange searchtext: string) { filtered = xmlparser.arrparseddata.filter({ (dict) -> bool in let tmp: nsstring = dict["title"]! let range = tmp.rangeofstring(searchtext, options: nsstringcompareoptions.caseinsensitivesearch) return range.location != nsnotfound }) if(filtered.count == 0) { searchactive = false; } else { searchactive = true; } self.tableview.reloaddata() }
your screenshot shows range.location = huge number. huge number nsnotfound (on 64-bit platforms); it's doing right thing.
Comments
Post a Comment