When I get the current user and then query my database in Parse, a bad access error appears. The code is in the viewDidLoad method. This is not all of the code in the viewDidLoad method. If more code is needed to diagnose the problem I will post it. I do not understand why this problem is happening. Thank you for your help in advance.
//Set table view delegate and data source
self.tableView.delegate = self;
self.tableView.dataSource = self;
//Set status bar style
[self setNeedsStatusBarAppearanceUpdate];
//Customize the tab bar
self.tabBarController.tabBar.tintColor = [UIColor colorWithRed:0.59 green:0.21 blue:0.21 alpha:1.0];
//Get the current user
currentUser = [PFUser currentUser];
if (currentUser) {
// do stuff with the user
if ([currentUser[@"role"] isEqualToString:@"UserOne"]) {
//Array
self.profiles = [NSMutableArray array];
PFQuery *queryForProfiles = [PFQuery queryWithClassName:@"_User"];
[queryForProfiles whereKey:@"gender" equalTo:currentUser[@"gender"]];
[queryForProfiles whereKey:@"role" equalTo:@"UserTwo"];
[queryForProfiles whereKey:@"location" equalTo:currentUser[@"location"]];
[queryForProfiles findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
// Do something with the found objects
for (PFObject *object in objects) {
//Add user to profiles array
[self.profiles addObject:object];
}
//Update the table view
[self.tableView reloadData];
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
}
self.tableView.layer.opacity = 0.0;
//Role of User
roleOfUser = currentUser[@"role"];
The error occurs at the line that starts the block for the query. [queryForProfiles findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {