Search code examples
swiftxcodeimageuikit

'InfoKey' is not a member type of 'UIImagePickerController'


I am getting this error:

'InfoKey' is not a member type of 'UIImagePickerController'

I had wasted time searching on the issue but failed.

private func imagePickerController(_ picker: UIImagePickerController,
                           didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    picker.dismiss(animated: true, completion: nil)
    guard let image = info[.originalImage] as? UIImage else {
        return
    }
}

Xcode 9.4, Swift 4.1


Solution

  • You are attempting to use the newer iOS 12 API which requires Xcode 10. If you are using Xcode 9.4 then you are using iOS 11 and you need to use the soon to be older API.

    private func imagePickerController(_ picker: UIImagePickerController,
                               didFinishPickingMediaWithInfo info: [String : Any]) {
        picker.dismiss(animated: true, completion: nil)
        guard let image = info[UIImagePickerControllerOriginalImage] as? UIImage else {
            return
        }
    }