Question

So I am able to store data into my parse class, but I can't read out the values.

this is where i declare a relationship between my Userinfo class and my User class :

 PFObject *userObject = [PFObject objectWithClassName:@"UserInfo"];
 [userObject setObject:[PFUser currentUser] forKey:@"Username"];

i then set values in the UserInfo class and it stores correctly, but when i go to read the values out of the database i get no objects were read out.

PFQuery *load =[PFQuery queryWithClassName:@"UserInfo"];
[load whereKey:@"Username" equalTo:[PFUser currentUser]];

[load findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
    if(!error)
    {
        if (!error) {
            infoArray = [[NSArray alloc] initWithArray:objects];
            NSLog(@"Successfully retrieved %d obj.", infoArray.count); //this comes back as zero
            NSLog (@"idummy %@", infoArray);
        }
    }
}];

I feel like I'm close but missing one step, I also checked I do not have any code executing in my - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions besides my parse key and client id.

UPDATE:

So i have figured out the above issue:

NSString *ObjID=curr.objectId;

PFQuery *load =[PFQuery queryWithClassName:@"UserInfo"];
[load whereKey:@"objectId" equalTo:ObjID];

it works when i @"adf234" for the equalTo, but is there for me to search based on the NSString ObjID value? Because it doesn't work when i put ObjID like i have above.

Was it helpful?

Solution

Simply change

PFQuery *load =[PFQuery queryWithClassName:@"UserInfo"];
/*[load whereKey:@"Username" equalTo:[PFUser currentUser]];*/ No need of this

[query includeKey:@"Username"];

[load findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
if(!error)
{
    if (!error)
    {
        NSDictionary *dict = [objects objectAtIndex:0];
        NSLog(@"Successfully retrieved %d obj.",[[dict objectForKey:@"Username"] objectForKey:@"username"]);  

      /* I was also getting it null but if you try to nslog [PFUSer currentUser] you will get details but I tried for object key pair then got details so similarly you will get all other details of user by providing different keys.*/
    }
}
}];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top