I tried this using Swift 5 and it is working without error. But the issue is with Swift 4.
First of all, if you're using Xcode 10.x I strongly suggest you to perform the Swift 5 update. Forget Swift 4 and stay updated.
Second, this is the right UIImagePickerControllerDelegate
implementation on Swift 5:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
// do stuff with your original image...
} else if let image = info[UIImagePickerController.InfoKey.editedImage] as? UIImage {
// do something with your edited image...
}
dismiss(animated: true, completion: nil)
}
Anyway, if you want to stick to Swift 4
, this is the ImagePicker delegate function to use:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage {
// do stuff with your image
} else if let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage {
// do stuff with your image
}
dismiss(animated:true, completion: nil)
}