saving PFObject in backgrounds

69 views Asked by At

in my app when i try to sign up the PFObjects are not saved in background (emailLabel, FirstNameLabel, LastNameLabel, PasswordLabel. any idea why

Here is is a code snippet

@IBAction func NextSignupPage(sender: AnyObject) {


let FirstNameObject = PFObject(className: "\(self.FirstNameLabel.text)")
FirstNameObject["First Name"] = "\(self.FirstNameLabel.text)"
FirstNameObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in

    }

let FamilyNameObject = PFObject(className: "\(self.FamilyNameLabel.text)")
FamilyNameObject["Family Name"] = "\(self.FamilyNameLabel.text)"
FamilyNameObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in

    }

let PasswordObject = PFObject(className: "\(self.PasswordLabel.text)")
PasswordObject["password"] = "\(self.PasswordLabel.text)"
PasswordObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
println("successfully signed Up.")
1

There are 1 answers

0
Acoop On

There are several problems that I see that might be causing the issues you are experiencing. First, as mentioned in the comments by flashadvanced, you should be using the Parse provided user.signUpInBackground to sign up new users. (Most importantly because Parse will encrypt your user's passwords. It seems as though you are planning on storing them as regular strings.) The docs to accomplish this can be found here.

In regards to creating PFObjects in general, it seems as though you want to create one PFObject that store the first name, family name and password. Your code above will create three different PFObjects that have no relationship to one another. In addition, you supply three different classes to the different PFObjects, another reason why they will not show up in the same class on the Parse server. The correct way of accomplishing this (considering that you should still be using the .signUpInBackground method and this applies only to other non- specific PFObjects) would be:

    let object = PFObject(className: "YourClassName")
    object["First Name"] = "\(self.FirstNameLabel.text)"
    object["Family Name"] = "\(self.FamilyNameLabel.text)"
    object["password"] = "\(self.PasswordLabel.text)"
    object.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
        println("successfully signed Up.")
    }