Search code examples
iosparse-platformpfquerypfuser

PFUser Query - Warning: Long-running operation is being executed on main thread - iOS


I am currently attempting to populate a table from an array of usernames.

In order to retrieve the usernames, I use a PFQuery, as explained in the parse documentation:

PFQuery *query = [PFUser query];
NSArray *users = [query findObjects];

This code technically works. However, I get this warning:

Warning: A long-running operation is being executed on the main thread.

I have tried using findObjectsInBackgroundWithBloc in order to retrieve the list of usernames. However, no data is retrieved. My table is empty.

The Parse documentation explains that querying users is a separate concept, different from querying normal objects, hence my code above. This code is taken straight from the Parse documentation.

Could anyone point me in the right direction?

Thanks, Miles


Solution

  • Your query is taking too much time to return data that's why you are getting this warning

    You can use findObjectsInBackgroundWithBlock: like this.

    PFQuery *query = [PFUser query];
    NSMutableArray *users;
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        users = [[NSMutableArray alloc]initWithArray:objects];
        [tableView reloadData];
    }
    }];