I would like to prevent the message "Cannot do a comparison query for type: (null)
" I don't want to resolve it, because I know what's going wrong, but I would like to put exception. If Query doesn't find anything... NSLog something. (instead of crash)
Here is my code :
PFQuery *requestsToCurrentUser = [PFQuery queryWithClassName:@"FriendRequest"];
[requestsToCurrentUser whereKey:@"to" equalTo:self.currentUser];
[requestsToCurrentUser whereKey:@"status" equalTo:@"pending"];
[requestsToCurrentUser findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
//this property stores the data for the tableView
self.friendRequests = objects;
//reload the table
[self.tableView reloadData];
} else {
//error occcurred
}
}];
try to put this
if(!self.currentUser){
// No value in self.currentUser
return;
}
PFQuery *requestsToCurrentUser = [PFQuery queryWithClassName:@"FriendRequest"];
[requestsToCurrentUser whereKey:@"to" equalTo:self.currentUser];
[requestsToCurrentUser whereKey:@"status" equalTo:@"pending"];
[requestsToCurrentUser findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
//this property stores the data for the tableView
self.friendRequests = objects;
//reload the table
[self.tableView reloadData];
} else {
//error occcurred
}
}];