2

We are trying out Parse server, and we have never used Parse SDK before. As part of learning we tried Facebook login with Parse, that worked good. Next we wanted to save the retrieved user information and we are stuck at saving the Profile picture.

The Code

let pictureURL = "https://graph.facebook.com/\(facebookID)/picture?type=large&return_ssl_resources=1"
let imageData = NSData.init(contentsOf: NSURL(string: pictureURL) as! URL)
let picture = PFFile(data: imageData! as Data)
PFUser.current()?.setObject(picture, forKey: "profilePicture")
PFUser.current()?.saveInBackground()

And it crashes on the line setObject with the following log:

crash log - image

Any help is much appreciated to get this issue resolved. Thanks!

2
  • try NSData instead of Data. Here: let picture = PFFile(data: imageData! as Data) Commented Sep 15, 2016 at 10:57
  • @Mr.UB It is public convenience init?(data: Data), thus not accepting NSData. However I tried this let picture = PFFile(data: (imageData! as NSData) as Data) and got the same error. Commented Sep 15, 2016 at 11:03

1 Answer 1

2

That happens when you pass Optional something to Any.

Try this:

    if let picture = PFFile(data: imageData! as Data) {
        PFUser.current()?.setObject(picture, forKey: "profilePicture")
        PFUser.current()?.saveInBackground()
    }

Or simply this, if you are sure that picture can never be nil:

    let picture = PFFile(data: imageData! as Data)
    PFUser.current()?.setObject(picture!, forKey: "profilePicture")
    PFUser.current()?.saveInBackground()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.