简体   繁体   中英

Null output for objectId in parse.com ios

I am trying to get objectId of babyInfo Class and want to link it to the User class of parse.com. But null objectId is being returned in all of these cases.

PFObject *babyInfo = [PFObject objectWithClassName:@"BabyInfo"];
babyInfo[@"babyname"] = babyname;
babyInfo[@"gender"] = gender;
babyInfo[@"dob"] = date;
  NSLog(@"Object ID: %@", babyInfo.objectId); //First method tried unsuccessfully
    [babyInfo saveInBackground];


  NSString *objectid=[babyInfo objectId];
    NSLog(@"%@",objectid);  // Second method tried unsuccessfully

    NSString *objectid= [babyInfo valueForKey:@"objectId"];
    NSLog(@"%@",objectid);  // Third method tried unsuccessfully

I think this is happening because you are using saveInBackground, so the log statements are logging null as the object hasn't saved yet. Also, your first log statement will definitely log null because it comes before the save statement. Try this:

PFObject *babyInfo = [PFObject objectWithClassName:@"BabyInfo"];
babyInfo[@"babyname"] = babyname;
babyInfo[@"gender"] = gender;
babyInfo[@"dob"] = date;

    [babyInfo save];


  NSString *objectid=[babyInfo objectId];
    NSLog(@"%@",objectid); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM