0

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.

3
  • 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?) Commented Jul 31, 2014 at 20:52
  • no, it's actually a variable, i'm getting the error: Implicit conversion of NSUInteger to PFUser is disallowed by ARC Commented Jul 31, 2014 at 21:02
  • indexOfObject are you sure you don't mean objectAtIndex? Commented Jul 31, 2014 at 21:09

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.