IPhone : Uploading changes to Parse PFUser Object not working

on Wednesday, April 8, 2015

I have created a simple iPhone application with a Parse Log In function. I then have a page that a button links to which is where the logged in user can view their profile.


To get this information and load it in the Profile page, I call the following loadData() function from the viewDidLoad():



func loadData() {

// DISPLAY PICTURE CODE
dpImage.image = UIImage(named: "profilePlaceholder")
dpImage.layer.cornerRadius = 50
dpImage.layer.masksToBounds = true

// Get and set Name and Degree
fullNameLabel.text = PFUser.currentUser()["fullName"] as? String
degreeLabel.text = PFUser.currentUser()["degree"] as? String

// Check degreeYear of user and create String
var degreeYear = String(PFUser.currentUser()["degreeYear"] as Int)

if (degreeYear == "1") {
degreeYear += "st Year"
} else if (degreeYear == "2") {
degreeYear += "nd Year"
} else if (degreeYear == "3") {
degreeYear += "rd Year"
} else {
degreeYear += "th Year"
}

// Get Group Contribution Rating and add % sign
var groupContribution = String(PFUser.currentUser()["groupContribution"] as Int) + "%"

// Set labels of cells
emailCell.detailTextLabel?.text = PFUser.currentUser().email
institutionCell.detailTextLabel?.text = PFUser.currentUser()["institution"] as? String
yearOfDegreeCell.detailTextLabel?.text = degreeYear
groupContributionCell.detailTextLabel?.text = groupContribution

}


This works fine. Then I have an edit button on the Profile page which links (modal segue) to a nearly identical page but with textfields instead of labels for each attribute.


On this Profile Edit page, clicking Save runs the following:



@IBAction func saveAction(sender: AnyObject) {

PFUser.currentUser()["fullName"] = fullNameTextField.text
PFUser.currentUser()["degree"] = degreeNameTextField.text
PFUser.currentUser().email = emailTextField.text
PFUser.currentUser()["institution"] = institutionTextField.text

self.dismissViewControllerAnimated(true, completion: nil)

}


The viewDidAppear function of the Profile page runs the loadData() function again to refresh the data on the label, which successfully updates the labels to the changed values.


BUT! My issue is that it doesn't seem to actually be uploading my changes to the Parse database. This is because when I log out and re-login to the app as the same user, I do not see the new updated profile attribute values, but the original values before changing them.


How do I push my changes that I am making in the Edit Profile page back to the Parse server?


NOTE: This is my first post to StackOverflow so let me know if I was not clear enough :)


0 comments:

Post a Comment