0

When trying to use the following function

func imagePickerController(picker: UIImagePickerController,didFinishPickingImage image: UIImage, editingInfo: [String: AnyObject]?) {
    let selectedImage:UIImage = (editingInfo[UIImagePickerControllerOriginalImage]) as! UIImage
    displayImage.image = selectedImage
    self.dismissViewControllerAnimated(true, completion: nil)
}

getting error: "Cannot subscript a value of type '[String:AnyObject]? with an index of type 'String'

on the second line where it I write the let selected Image

This has worked fine with Xcode 6.3 & 6.4 but now with new Xcode 7 beta 4 does not work and throws an error.

Help!

2 Answers2

0

Try dismissing controller before setting image to imageView.
replace your methods as:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
 self.dismissViewControllerAnimated(true, completion: nil)
let selectedImage:UIImage = (editingInfo[UIImagePickerControllerOriginalImage]) as! UIImage
displayImage.image = selectedImage

}
iAnurag
  • 9,286
  • 3
  • 31
  • 48
0

I have figured it out the answer looking in the documentation of imagePickerController. the method I had to use is didFinishPickingMediaWithInfo instead and as follows:

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

    let selectedImage:UIImage = (info[UIImagePickerControllerOriginalImage]) as! UIImage
    displayImage.image = selectedImage
    self.dismissViewControllerAnimated(true, completion: nil)
}