0
votes

I am trying to get an object related to my user object. I've tried numerous methods...

this one gets the user object but I don't get the reputation object.

PFuserProfile = [PFQuery getUserObjectWithId:userObj];
PFuserRep = PFuserProfile[@"reputation"];

this one I have an error on the last line.

PFQuery *query = [PFUser query];
[query whereKey:@"objectId" equalTo:userObj];
[testQuery includeKey:@"reputation"];
NSArray *wtf = [query findObjects];
PFuserProfile = [wtf indexOfObject:0];

I've tried some other methods but not sure the best one, I can't get any of them to work... here's the last one where I get an error in setting the profile.

[query whereKey:@"objectId" equalTo:userObj];
[query includeKey:@"reputation"];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
   if(!error){
       PFuserProfile = [objects indexOfObject:objects.firstObject];
   }
}];

Thank you.

1
Your second one looks like it should work except you have omitted the variable name after PFUserProfile (I am assuming PFUserProfile is a class since it begins with an upper case P - if it is actually your variable name, what error do you get?)Paulw11
no, it's actually a variable, i'm getting the error: Implicit conversion of NSUInteger to PFUser is disallowed by ARCBryanzpope
indexOfObject are you sure you don't mean objectAtIndex?William George

1 Answers

1
votes

Make sure that when you select an object from a dictionary use: objectAtIndex:

Therefore you will need to update your code to the following

PFQuery *query = [PFUser query];
[query whereKey:@"objectId" equalTo:userObj];
[testQuery includeKey:@"reputation"];
NSArray *wtf = [query findObjects];
PFuserProfile = [wtf objectAtIndex:0];

Better yet, because you can get an out of bounds exception with objectAtIndex: you can replace the last line with:

PFuserProfile = [wtf firstObject];

This will not crash your application if the query returned no objects.