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);
Related
In the docs https://www.parse.com/docs/ios/guide#relations-using-pointers
it says that in the example provided you can find the User who created the game
// say we have a Game object
PFObject *game = ...
// getting the user who created the Game
PFUser *createdBy = [game objectForKey:#"createdBy"];
But when I use the exact syntax since I want to populate the pointer in my "user" column
PFUser *user = [PFUser currentUser];
NSString *username = user.username;
// Inside my queryForTable method so PFObject is returned in
// tableView:cellForRowAtIndexPath:object
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"fromUser = %#", user];
PFQuery *query = [PFQuery queryWithClassName:#"Activities" predicate:predicate];
// Inside tableView:cellForRowAtIndexPath:object
PFUser *createdBy = [object objectForKey:#"user"];
NSLog(#"User to user ---%#", createdBy);
But All I get back is
User to user ---<PFUser: 0x7ff9024da860, objectId: aOisP569e3, localId: (null)> {
// Nothing here
}
If I'm understanding correctly, am I also supposed to get back username, email etc in my user object?
---UPDATE 1---
looking at the Anypic app provided by parse it should return something like this
<PFUser: 0x7f7ff9fafc00, objectId: LfADtx1K2J, localId: (null)> {
// Stuff appears here
displayName = "poopiu";
facebookId = 130941340571204;
profilePictureMedium = "<PFFile: 0x7f7ff9faf500>";
profilePictureSmall = "<PFFile: 0x7f7ff9faf7f0>";
username = I34MBM3WYSB5tjWIIvUvhH5fq;
}
but mine is empty even though I have a column called username that isn't undefined so I should get that inside my PFUser object
--UPDATE 2--
Here's what I get back from logging object like so...
NSLog(#"Object---%#", object);
<Activities: 0x7fbbebf42d20, objectId: rDwYI5Inuk, localId: (null)> {
user = "<PFUser: 0x7fbbee1367e0, objectId: SFL0kVZ17x>";
status = 0;
>
Add the following method call after you instantiated your query.
[query includeKey: "user"];
By default, queries do not grab information past the immediate object that was queried.
Are you sure your user isn't nil? According to the docs you must be logged in for currentUser to return a user object.
[createdBy fetch];
NSLog(#"User to user ---%#", createdBy);
Try this hope this will help
I've been using Parse.com for two months, but this is the first time I get a stupid error which I can't figure out.
I've been working in an app for iOS, but in the beginning I've been working with my own user. Now I registered other users and I want to fetch them from the server.
Well, I add one object in the table Changes, where I have a user property which is a Pointer<User> (it's not _User, but User, it's custom, just an object). Well, when I try to fetch all the rows I have, the one that I have with my user are ok:
so in my debug console is like :
but when I fetch other users:
my debug console is:
so there's not any variable!!!! :(
This is my code:
PFQuery *closestChanges = [PFQuery queryWithClassName:#"Changes"];
[closestChanges whereKey:#"coordinates" nearGeoPoint:geoPoint withinKilometers:0.5f];
[closestChanges findObjectsInBackgroundWithBlock:^(NSArray *changes, NSError *error) {
arrayChanges0 = [[NSMutableArray alloc] init];
arrayChanges1 = [[NSMutableArray alloc] init];
if (changes == nil && changes.count == 0) {
[_tableView reloadData];
return;
}
for (int i = 0; i < changes.count; i++) {
PFObject *currentChange = [changes objectAtIndex:i];
PFObject *user = [currentChange valueForKey:#"user"]; // here my user is null when it's other users.
PFObject *changeToStore = [PFObject objectWithClassName:#"Changes"];
[changeToStore setValue:currentChange[#"changetype"] forKey:#"type"];
[changeToStore setValue:currentChange[#"quantity"] forKey:#"quantity"];
[changeToStore setValue:currentChange[#"date"] forKey:#"enddata"];
[changeToStore setValue:user forKey:#"user"];
if ([currentChange[#"changetype"] intValue] == 0)
[arrayChanges0 addObject:changeToStore];
else
[arrayChanges1 addObject:changeToStore];
}
[_tableView reloadData];
}];
Is there anything wrong I'm doing by adding new users???
Thank you very much in advance.
When you fetch a pointer type from a table, you will only get back the metadata which is objectId. You need to call - (instancetype)includeKey:(NSString *)key in order to get all the data back from Changes table. If you query directly from User table, you will get all the data. But in this case, you User object is a subdocument from Changes objects.
Add this line before performing querying:
[closestChanges includeKey:#"user"]
I am trying to get the objectId key from a PFUser using Parse.com, but it keeps returning null.
PFUser *me = [PFUser currentUser];
NSString *theObject = me[#"objectId"];
NSLog(#"Return %#", theObject);
Every time I run this, it comes back as "Return null". I can put username in where I type objectId, and will get a result, but not for objectId.
Try:
NSString *theObject = [me objectId];
From:
Getting objectId from parse.com
I have a PFObject class where each object has a user attached to it. I can call each object and display it in a tableview, however when I try to call the associated PFUser to each object it just crashes.
PFObject *owner = [self.objectArray objectAtIndex:indexPath.row];
NSString *ownerString = [owner objectForKey:#"user"];
cell.detailTextLabel.text = ownerString;
Is there another way I need to call the user to get the username? In the NSLog the user looks like this: user = \"<PFUser:dDeHnc33EE>\";\n
PFUser is not an NSString, it's a subclass of PFObject which again is a subclass of NSObject. PFUser has a property called username which returns a string. Do this:
PFUser *user = [owner objectForKey:#"user"];
NSString *username = user.username;
to get the username of the user. Check of the PFUser documentation here.
I am using parse.com to get the data like given below. I already created the data base using sqlite manager.
- (IBAction)button:(id)sender {
PFQuery *postQuery = [PFQuery queryWithClassName:#"movie"];
//movie is the class name in the parse.com in that two columns store the data
[postQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
//Save results and update the table
self.postArray = objects;
NSLog(#"array....%#",self.postArray);
// [spinner startAnimating];
[self.myTable reloadData];
}
}];
}
- (void)getTheData:(id)sender {
//it is sqlite query class
model=[[DataModel alloc]init];
//here insertQuery method to send the columns class object(buk).
[model insertInformIntoDB:buk];
PFObject *post = [self.postArray objectAtIndex:indexPath.row];
NSLog(#"posttttt......%#",post);
//here parse.com column name to send the data into sqlite Columns
buk.name=[post objectForKey:#"name"];
buk.Hero=[post objectForKey:#"Hero"];
}
I got the output like this:
//this is overall movie class
array....(
"<movie:EHx3UonJmw:(null)> {\n Hero = Mahesh;\n name = pokiri;\n num = 222;\n}",
"<movie:zekgTzIsLs:(null)> {\n Hero = pawan;\n name = jhoni;\n num = 412;\n}",
"<movie:0z3ZkI4lvB:(null)> {\n Hero = Prabhas;\n name = darling;\n num = 312;\n}"
)
posttttt......<movie:EHx3UonJmw:(null)> {
Hero = Mahesh;
name = pokiri;
num = 222;
}
Error:-
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSMutableString stringWithUTF8String:]: NULL cString'
but here geting null values in buk.name and Hero....
You question is so confusing but still I would love to show what might be wrong,
[model insertInformIntoDB:buk]; should be at the end of the method where you set the properties of the buk variable
-(void)getTheData:(id)sender{
//it is sqlite query class
model=[[DataModel alloc]init];
//here insertQuery method to send the columns class object(buk).
//inserting the buk without setting the values, so move this statement at the end
//[model insertInformIntoDB:buk];
PFObject *post = [self.postArray objectAtIndex:indexPath.row];
NSLog(#"posttttt......%#",post);
//here parse.com column name to send the data into sqlite Columns
buk.name=[post objectForKey:#"name"];
buk.Hero=[post objectForKey:#"Hero"];
//save the buk
[model insertInformIntoDB:buk];
}