0

I am trying to develop an application that have a sign-up page, in fact I am using Parse.com for the database, I've used the PFUser for the (Username,password, Email) and it works so fine, but it happen that I have additional information in the signup page such as (name,DOB and location) so when I added them I got an error:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use nil for keys or values on PFObject. Use NSNull for values.

Note that I have a table that name User (The default one that parse provide) and I want to add the (name,DOB and the location) to that table User but I get that error.

Here is my code

- (void) Registeruser {

    PFUser *newUser = [PFUser user];
    newUser.username = UserNameS.text;
    newUser.email= EmailS.text;
    newUser.password=PasswordS.text;
    PFObject * newUser1 = [PFObject objectWithClassName:@"User"];
    newUser1[@"name"]= NameS.text;
    newUser1[@"gender"]= genderS.text;
    newUser1[@"Location"]=genderS.text;
    NSString *dateStr = DOBS.text;
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
   [dateFormat setDateStyle:NSDateFormatterLongStyle];
    [dateFormat setTimeStyle:NSDateFormatterShortStyle];
    NSDate *date = [dateFormat dateFromString:dateStr];

  newUser1[@"dateofBirth"]=date;


    [newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (!error) {
            NSLog(@"Registration success!");
            UserNameS.text = nil;
            PasswordS.text = nil;
           EmailS.text = nil;
            NameS.text=nil;
           DOBS.text=nil;
           LocationS.text=nil;
            genderS.text=nil;
            [self performSegueWithIdentifier:@"login" sender:self];}
        else {
            NSLog(@"There was an error in registration");
        }}];}

1 Answer 1

2

The problem is that one of the objects you're trying to add to your PFObject doesn't exist. I can't say for sure, but I'm betting that your problem is here:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateStyle:NSDateFormatterLongStyle];
[dateFormat setTimeStyle:NSDateFormatterShortStyle];
NSDate *date = [dateFormat dateFromString:dateStr];

newUser1[@"dateofBirth"] = date;

Are you sure that the date is setting properly?

Try NSLog to make sure your date is valid before saving. If that doesn't work repeat until you find the nil value. A trick that I use that makes me feel better is to use this:

This:

newUser1[@"name"]= NameS.text;
newUser1[@"gender"]= genderS.text;
newUser1[@"Location"]=genderS.text;

Could be:

if (NameS.text) newUser1[@"name"]= NameS.text;
if (genderS.text) newUser1[@"gender"]= genderS.text;

if (date) newUser1[@"dateofBirth"] = date;

if (objectYouWantToAdd) yourPFObject[@"someKey"] = objectYouWantToAdd;

That way, we check if the object exists before trying to add it.

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.