1

I would like my user to add/edit details about their profile after they register with my app.

@IBAction func doneEditting(sender: AnyObject) {
    self.completeEdit()
}

func completeEdit() {
    var user = PFUser()
    user["location"] = locationTextField.text

    user.saveInBackgroundWithBlock {
        (succeeded: Bool, error: NSError?) -> Void in
        if let error = error {
            let errorString = error.userInfo?["error"] as? NSString
            println("failed")
        } else {
            self.performSegueWithIdentifier("Editted", sender: nil)
        }
    }
}

the breakpoint stops right at user.saveInBackgroundWithBlock. No of the docs show how to append new columns after the signup.

Thanks!

ishkur88
  • 1,265
  • 2
  • 9
  • 12

2 Answers2

5

You are mentioning that the user should be able to edit their profile after they have registered. When registering a user with Parse using signUpInBackgroundWithBlock, then the Parse SDK will automatically create a PFUser for you.

In your provided code you are creating and saving a completely new PFUser instead of getting the one which is currently logged in. If you are not using the PFUser which is logged in, then you will get the following error at user.saveInBackgroundWithBlock (which you are also mentioning in your post):

User cannot be saved unless they are already signed up. Call signUp first

To fix this, you will need to change:

var user = PFUser()

To the following:

var user = PFUser.currentUser()!

The rest of your code (for example user["location"] = locationTextField.text) works fine and will dynamically/lazily add a new column to your User database (which is what you want).

Kumuluzz
  • 2,012
  • 1
  • 13
  • 17
0

Parse allows you to add columns to a class lazily, meaning that you can add a field to your PFObject and if it is not present in your Parse class, Parse will add that column for you.

Here's example how you would add a column via code:

// Add the new field to your object
yourObject["yourColumnName"] = yourValue
yourObject.saveInBackground()

You'll notice that Parse will create a new column named yourColumnName on their web portal.

reference from HERE.

Community
  • 1
  • 1
Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
  • Thank you! I will try this, in the meantime I just created all of the parts of class during sign up and left blank values and then hid them until the user changed them. – ishkur88 Jul 11 '15 at 05:41