Im re-writing an iOS app I made using C# and Xamarin to Swift for obvious reasons of Xamarin\'s pricing, and low documentation. Following this tutorial for including a UIS
Because I think type of your self.records
is [Record]
and you are trying to casting it as single Record
which is not an Array
. So it is not possible.
Try this:
let array = (self.records as [Record]).filteredArrayUsingPredicate(searchPredicate)
UPDATE:
Update your updateSearchResultsForSearchController
method like this:
func updateSearchResultsForSearchController(searchController: UISearchController)
{
self.filteredRecords.removeAll(keepCapacity: false)
self.filteredRecords = self.records.filter() {
($0.album.lowercaseString).containsString(searchController.searchBar.text!.lowercaseString)
}
self.tableView.reloadData()
}
If you want to search for both album
and artist
then replace this line:
($0.album.lowercaseString).containsString(searchController.searchBar.text!.lowercaseString)
with this line:
($0.album.lowercaseString).containsString(searchController.searchBar.text!.lowercaseString) || ($0.artist.lowercaseString).containsString(searchController.searchBar.text!.lowercaseString)