0
votes

For the updateSearchResultsForSearchController:searchController method is it possible to filter through an array of PFUsers? My table presents a list of users and I would like to filter through the users through the search bar.

I've found source of the problem and it's this

NSPredicate *resultPredicate = [NSPredicate
                                predicateWithFormat:@"SELF contains[c] %@",
                                searchText];
searchResults = [[searchResults filteredArrayUsingPredicate:resultPredicate] mutableCopy];

Where searchResults is assigned to self.objects returned from the parse query.

I think the problem is that it's comparing "SELF" a PFUser object to a string so my app breaks, so I tried to replace "SELF" with "SELF.username" but for some reason that breaks too. The only time my app will run without breaking is if I just assign searchResults to an array of strings not PFUser objects, but I need the PFUser objects so I was wondering if it's possible to use NSPredicate on an array of PFUser Objects?

1

1 Answers

0
votes

Okay...Nevermind it's possible I just made a dumb error

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.username CONTAINS[cd] %@", searchText];

Is the correct way, just grab the username off of the object. So it turns out in my separate UITableViewController to present new search results, I wasn't using "objectForKey=@"username"" when trying to present the usernames in my cell so that's why my app was crashing not because of the syntax for the predicate