Reputation: 11175
I am trying to search through an array of objects that are retrieved from Parse to display the results in a UITableView
. I tried using the same method that I used in one of my other apps, but in that case it was just searching through an array of strings.
This is my code at the moment:
func filterContentForSearchText(searchText: NSString) {
let resultPredicate = NSPredicate(format: "SELF beginswith[cd] %@", searchText) //Use either contains or beginswith
searchResults = DataManager.sharedInstance.rideArray.name.filteredArrayUsingPredicate(resultPredicate)
}
func searchDisplayController(controller: UISearchDisplayController!, shouldReloadTableForSearchString searchString: String!) -> Bool {
self.filterContentForSearchText(searchString)
return true
}
I understand why it doesn't work, but I can't figure out a solution to the problem. The property that I want to search for within the 'Ride' object is name.
Can anyone help me out? Thanks!
Upvotes: 0
Views: 45
Reputation: 80265
Assuming rideArray
is an array of Parse objects that have a property name
, the predicate should be
NSPredicate(format: "name beginswith[cd] %@", searchText)
And you filter the array with
rideArray.filteredArrayUsingPredicate(searchPredicate)
Upvotes: 1