0

I was trying to set up the sign up page so that the user can set up a profile picture but as soon as i press the sign up button and it segues to the signup page it keeps crashing because of the profile picture codes. This is the button to set the profile picture

    @IBAction func setProfilePicture(sender: AnyObject) {
    let myPickerController = UIImagePickerController()
    myPickerController.delegate = self
    myPickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
    self.presentViewController(myPickerController, animated: true, completion: nil)
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

    profilePictureIV.image = info[UIImagePickerControllerOriginalImage] as? UIImage
    self.dismissViewControllerAnimated(true, completion: nil)
}

and this is the code to send the data to parse in the viewDidLoad() method

    let newUser = PFUser()
          let profilePicture = UIImageJPEGRepresentation((profilePictureIV?.image)!, 1)
          if(profilePicture != nil) {
              let profilePictureImageFile = PFFile(data: profilePicture!)
              newUser["profilePicture"] = profilePictureImageFile
          }
          ...
    }

The line that keeps crashing is the let profilePicture.... line giving an error: fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

4

1 に答える 1

0

アンラップ中に is nil だとエラーprofilePictureIV?.imageになるので確認

let newUser = PFUser()
if let profilePicture = UIImageJPEGRepresentation(profilePictureIV?.image, 1) {
   let profilePictureImageFile = PFFile(data: profilePicture)
   newUser["profilePicture"] = profilePictureImageFile
}

また

let newUser = PFUser()
if let profilePictureImage = profilePictureIV?.image {
   let profilePicture = UIImageJPEGRepresentation(profilePictureImage, 1)!
   let profilePictureImageFile = PFFile(data: profilePicture)
   newUser["profilePicture"] = profilePictureImageFile
}
于 2015-09-29T13:18:17.927 に答える