0
votes

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) {

1
So, where does the error occur??? - Hot Licks
The error occurs at the line that starts the block for the query. [queryForProfiles findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { - shadowme
Where is the exception traceback showing that? - Hot Licks
That's the last line before the app crashes. - shadowme
And it says LookUpImpOrForward on the left as the last call. - shadowme

1 Answers

0
votes

Shadowme,

I'm sorry, a horrible mistake on my part. Your code was visually full I kind of skimmed through it too fast. You can't query the user class the way you have structured it.

To query a user class you simply do the following:

PFQuery *queryForProfiles = [PFUser query];