Search code examples
iosswiftparse-platformpfuser

Create a User with Profile Picture with Parse in Swift


How would I create a sign up page using Parse where I could also get the user to input there own profile picture in Swift.


Solution

  • Please check below code , add a photo fields into your user table with parse.com

     var user = PFUser()
    
        let imageData = UIImageJPEGRepresentation(userDetails.getPhoto(), 0.05)
        let imageFile = PFFile(name:"image.jpg", data:imageData)
        imageFile.save()
    
        user.username = usrEntered
        user.password = pwdEntered
        user.email = emlEntered
    
        user.setObject(imageFile, forKey: "photo")
    
        user.signUpInBackgroundWithBlock {
            (succeeded: Bool!, error: NSError!) -> Void in
                if error == nil {
                   // Hooray! Let them use the app now.
                   self.messageLabel.text = "User Signed Up";
                } else {
                    // Show the errorString somewhere and let the user try again.
                }
        }