This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test() { | |
alert('this is a test'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func fetchData() { | |
do { | |
items = try context.fetch(Item.fetchRequest()) | |
filteredData = items | |
DispatchQueue.main.async { | |
self.tableView.reloadData() | |
} | |
} catch { | |
print("Couldn't Fetch Data") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { | |
if searchText.isEmpty { | |
filteredData = items | |
} else { | |
filteredData = items.filter { ($0.name?.lowercased().contains(searchText.lowercased()))! } | |
} | |
DispatchQueue.main.async { | |
self.tableView.reloadData() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
} else { | |
filteredData = items.filter { ($0.name?.lowercased().contains(searchText.lowercased()))! } | |
} | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { | |
if searchText.isEmpty { | |
filteredData = items | |
} else { | |
// filter the array here, then update table | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DisplayTableViewController: UITableViewController, UISearchBarDelegate { | |
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext | |
var items: [Item] = [] | |
var selectedIndex: Int! | |
var filteredData: [Item] = [] | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DisplayTableViewController: UITableViewController, UISearchBarDelegate { | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createSearchBar() { | |
let searchBar = UISearchBar() | |
searchBar.showsCancelButton = false | |
searchBar.placeholder = "Search" | |
searchBar.delegate = self | |
self.navigationItem.titleView = searchBar | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func updateAction(_ sender: Any) { | |
guard let newEntry = entryText.text else { | |
return | |
} | |
item.name = newEntry | |
(UIApplication.shared.delegate as! AppDelegate).saveContext() | |
dismiss(animated: true, completion: nil) | |
} |