Reputation: 5559
I am using parse.com to create my swift app backend.
I want to add columns to my user and then refer to the current user's new columns/fields throughout my code.
What is the best way to do this?
When I create my user in my swift code I add the columns
func signUpViewController(signUpController: PFSignUpViewController!, didSignUpUser user: PFUser!) {
user["points"] = 0
user.saveInBackgroundWithBlock { (success: Bool!, error: NSError!) -> Void in
if success == false || error != nil {
println(error)
}
}
I tried creating a User class which inherited from PFUser
class User: PFUser {
var points = 0
}
I want to be able to check if the user has points in various controllers. I tried something like this
var query = PFUser.query()
query.whereKey("user", equalTo:PFUser.currentUser().username)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
var user = objects.first? as? User
if user != nil {
if user!["points"] as Int == 0 {
println("You have no points")
}
}
}
}
I also tried:
var points = PFUser.currentUser()["points"]
Upvotes: 0
Views: 871
Reputation: 2992
There is additional field to fill in. For example, I have one extra field to fill in the password one more time. I make it like this: In viewDidLoad method:
// Change "Additional" to "Confirm password"
[self.signUpView.additionalField setPlaceholder:NSLocalizedString(@"Confirm password",nil)];
Remember also to set the position of this field in viewDidLayoutSubviews method
[self.signUpView.additionalField setFrame:CGRectMake(fieldFrame.origin.x + 5.0f,fieldFrame.origin.y + yOffset+ 35.0f,fieldFrame.size.width - 10.0f, fieldFrame.size.height)];
Upvotes: 0
Reputation: 1164
You could just refresh the user in background then the user object will contain the new/refresh data/fields.
Upvotes: 1