filtering results in using containsAllObjectsInArray
I am trying to filter results into a searchDisplayController by searching
objects on parse.com. I can successfully search the objects and display
them using containsString but that is not how I want to search the
objects. I would like to search the objects using
containsAllObjectsInArray. I don't know if I am going about this the
correct way but anyway here's the code that I am trying:
- (void)filterResults:(NSString *)searchTerm {
NSCharacterSet *whitespaces = [NSCharacterSet whitespaceCharacterSet];
NSPredicate *noEmptyStrings = [NSPredicate predicateWithFormat:@"SELF !=
''"];
NSArray *parts = [searchTerm
componentsSeparatedByCharactersInSet:whitespaces];
NSArray *filteredArray = [parts filteredArrayUsingPredicate:noEmptyStrings];
NSLog(@" filteredArray equals %@", filteredArray);
[self.searchResults removeAllObjects];
PFQuery *query = [PFQuery queryWithClassName: @"Items"];
[query whereKeyExists:@"itemName"];
[query whereKeyExists:@"itemDescription"];
[query whereKey:@"itemName" containsAllObjectsInArray:filteredArray];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if(!error){
for (PFObject *object in objects){
NSLog(@"%@", objects);
NSLog(@"%u", objects.count);
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.searchResults removeAllObjects];
[self.searchResults addObjectsFromArray:objects];
[self.searchDisplayController.searchResultsTableView reloadData];
});
} else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
In my output I am receiving the error: "code = 102; error = "$all only
works on array fields";" I don't understand why this doesn't work as
filtered array is obviously an array and the filtered array is being
produced correctly in output.
No comments:
Post a Comment