Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Sean Lee
5,196 PointsData passing through ViewControllers works fine in simulator but crashes in app (PFObject nil)
Error Message - * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use nil for keys or values on PFObject. Use NSNull for values.'
When I do a NSLog check from the simulator, the value I passed from my previous VC prints out in the console and everything looks fine, but when I run it in the iOS device, NIL is passed from the previous VC causing the app to crash...
Anyone know why it might be doing that?
PFUser *currentUser = [PFUser currentUser];
NSLog(@"currentUser objectId ----- %@",currentUser.objectId);
NSLog(@"Value transferred from previous VC: %@", _transferName);
if (_transferName == nil || _transferStreet == nil || _transferCity == nil || _transferState == nil || _transferZip == nil || _transferEmail == nil || _transferPhone == nil) {
NSLog(@"Can't use nil for keys or values on PFObject. Use NSNull for values");
NSLog(@"Checking for nil: %@", _transferName);
NSLog(@"Checking for nil: %@", _transferStreet);
NSLog(@"Checking for nil: %@", _transferCity);
NSLog(@"Checking for nil: %@", _transferState);
NSLog(@"Checking for nil: %@", _transferZip);
NSLog(@"Checking for nil: %@", _transferEmail);
NSLog(@"Checking for nil: %@", _recepientName);
NSLog(@"Checking for nil: %@", _recepientPhone);
NSLog(@"Checking for nil: %@", _recepientStreet);
NSLog(@"Checking for nil: %@", _recepientCity);
NSLog(@"Checking for nil: %@", _recepientState);
NSLog(@"Checking for nil: %@", _recepientZip);
}
else {
PFObject *order = [PFObject objectWithClassName:@"Orders"];
order[@"senderName"] = _transferName;
order[@"senderStreet"] = _transferStreet;
order[@"senderCity"] = _transferCity;
order[@"senderState"] = _transferState;
order[@"senderZip"] = _transferZip;
order[@"senderEmail"] = _transferEmail;
order[@"senderPhone"] = _transferPhone;
order[@"recepientName"] = _recepientName;
order[@"recepientPhone"] = _recepientPhone;
order[@"recepientStreet"] = _recepientStreet;
order[@"recepientCity"] = _recepientCity;
order[@"recepientState"] = _recepientState;
order[@"recepientZip"] = _recepientZip;
[order saveInBackground];
}