0

I am new to swift, I am using swift 3. I am trying to pick multiple image from photo library and I am using ELCimagepickercontroller However when I am trying to read the images from the array I got error: Type 'Any' has no subscript members My Code as below: please let me know what's wrong

func elcImagePickerController(_ picker: ELCImagePickerController!, didFinishPickingMediaWithInfo info: [Any]!) {   
            self.dismiss(animated: true, completion: nil)
            var i = 0
            for item in info as [AnyObject]
            {
                i += 1

 var imageview = UIImageView(image: (info[UIImagePickerControllerOriginalImage] as? [String]))         
                     // var name = .uiImageJPEGRepresentation()!
            }
}
rania
  • 57
  • 7
  • whats the need for 'item' and 'i' in your for-loop? Where _exactly_ does the error occur? – Yohst Nov 29 '16 at 03:16
  • thank you for you trying to help- got it now. the i and item I have not used it yet as I kept on getting the error. – rania Nov 30 '16 at 17:01

1 Answers1

0

Since the info parameter is an array of dictionaries, you need to properly cast item in your for loop.

func elcImagePickerController(_ picker: ELCImagePickerController, didFinishPickingMediaWithInfo info: [Any]) {
    self.dismiss(animated: true, completion: nil)

    for item in info as [String : Any]
    {
        if let image = item[UIImagePickerControllerOriginalImage] as? UIImage {
            var imageview = UIImageView(image: image)
        }
    }
}

There were several other issues in your code. Don't needlessly add !. In fact, avoid all uses of ! until you fully comprehend their proper use. Until then, each use is a potential crash.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Glad to help. Please don't forget to accept answers that solve your questions by clicking the checkmark to the left of the answer. – rmaddy Nov 30 '16 at 17:01