I'm trying to upgrade to upgrade my project to Swift 2 but I stuck on the following error:
Contextual type 'AnyObject' cannot be used with array literal
Here's my code:
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
let data = UIImageJPEGRepresentation(image, 0.08)
let file = PFFile(data: data!)
PFUser.currentUser()!["Picture"] = [file]
try! PFUser.currentUser()!.save()}
And here’s the line where the problem occur
PFUser.currentUser()!["Picture"] = [file]
Thanks a lot for your help !! (I'm beginner,...)
substitute this line:
PFUser.currentUser()!["Picture"] = [file]
with:
PFUser.currentUser()!["Picture"] = file
Edit: As noted, it is better practice to not force unwrap a conditional and do something as follows:
guard let user = PFUser.currentUser() else {
return
}
user["Picture"] = file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With