Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. {
  2. studentId = 1437404654;
  3. name = "Rancho";
  4. },
  5. {
  6. studentId = 1932617669;
  7. name = "Mastora";
  8. },
  9. {
  10. studentId = 1457367179;
  11. name = "Amanda";
  12. }
  13.  
  14. {
  15.  
  16. return myArr.count
  17.  
  18. }
  19.  
  20. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
  21.  
  22. {
  23. let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MyCell
  24.  
  25. cell.idTextField.text = (dict.value(forKey: "studentId") as! String)
  26.  
  27. cell.nameTextField.text = (dict.value(forKey: "name") as! String)
  28.  
  29. }
  30.  
  31. func searchBarTextDidEndEditing(_ searchBar: UISearchBar)
  32.  
  33. }
  34.  
  35. func searchBarCancelButtonClicked(_ searchBar: UISearchBar)
  36.  
  37. }
  38.  
  39. func searchBarSearchButtonClicked(_ searchBar: UISearchBar)
  40.  
  41. }
  42.  
  43. func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String)
  44.  
  45. let predicate = NSPredicate(format: "%K CONTAINS[cd] %@ OR %K CONTAINS[cd] %@", "studentId", searchText, "name", searchText)
  46.  
  47. let sorted = copyArr.filter({
  48.  
  49. return predicate.evaluate(with: $0)
  50.  
  51. })
  52.  
  53. print(sorted)
  54.  
  55. myArr.removeAllObjects()
  56.  
  57. if sorted.count==0
  58. {
  59.  
  60. myArr.addObjects(from: copyArr as! [Any])
  61.  
  62. }
  63. else
  64.  
  65. {
  66. myArr.addObjects(from: sorted)
  67.  
  68. }
  69.  
  70. resultTable.reloadData()
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement