Swift 4.2 imagePickerController issue
like this
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
picker.dismiss(animated: true, completion: nil)
let image = info[UIImagePickerController.InfoKey.originalImage]! as! UIImage
...
}
In Swift 4.2 imagePickerController delegate methods has changed a bit. Kindly check out the below code.
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
var selectedImage: UIImage?
if let editedImage = info[.editedImage] as? UIImage {
selectedImage = editedImage
self.profileImage.image = selectedImage!
picker.dismiss(animated: true, completion: nil)
} else if let originalImage = info[.originalImage] as? UIImage {
selectedImage = originalImage
self.profileImage.image = selectedImage!
picker.dismiss(animated: true, completion: nil)
}
}
This will work for sure.
The method signature has changed to
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
You should see a warning message for the func name
Instance method 'imagePickerController(:didFinishPickingMediaWithInfo:)' nearly matches optional requirement 'imagePickerController(:didFinishPickingMediaWithInfo:)' of protocol 'UIImagePickerControllerDelegate'
Candidate has non-matching type '(UIImagePickerController, [String : Any]) -> ()'
Move 'imagePickerController(_:didFinishPickingMediaWithInfo:)' to another extension to silence this warning
Make 'imagePickerController(_:didFinishPickingMediaWithInfo:)' private to silence this warning
Requirement 'imagePickerController(_:didFinishPickingMediaWithInfo:)' declared here (UIKit.UIImagePickerControllerDelegate)