Mark Li Mark Li - 6 months ago 17
Swift Question

Parse "cannot sign up without username"

I made a user sign up system with parse, but it keeps saying "cannot signup without username" even if there is a string passed to PFUser's username property. What causes this error?

let user = PFUser()
user.signUpInBackgroundWithBlock{(success:Bool,error:NSError?)-> Void in if error==nil{
user.username = self.username.text!
user.password=self.Password.text!
user.email=self.Email.text!
self.navigationController?.pushViewController(UploadImageViewController(),animated:true)
}
else {let errorMessage: String = error!.userInfo["error"] as! String;self.displayErrorMessage(errorMessage)}
}

Answer

You have to actually assign those properties before you call signUpInBackgroundWithBlock

Something like this:

let user = PFUser() 
user.username = self.username.text!
user.password=self.Password.text!
user.email=self.Email.text!

user.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
if let error = error {
let errorString = error.userInfo["error"] as? NSString
// Handle the error
} else {
// Push your view controller
}
}
Comments