Swift 4.2 imagePickerController issue

uiimagepickercontroller mediatypes swift 4
uiimagepickercontroller swift 5
uiimagepickercontroller camera and photo library swift
get image url from uiimagepickercontroller swift 4
multiple image picker swift 4
uiimagepickercontroller crop image swift
uiimagepickercontroller select multiple images swift 5
uiimagepickercontroller ios 13

Trying to pass chat client from swift 4 to swift 4.2 and with picker i found trouble.

UIImagePickerControllerEditedImage Cannot subscript a value of type '[String : Any]' with an index of type 'UIImagePickerController.InfoKey'

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

    if let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
        self.userProfileImage.contentMode = .scaleAspectFit
        self.userProfileImage.image = pickedImage
    }

    picker.dismiss(animated: true, completion: nil)
}

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)

Swift 4.2 Cannot convert value of type '(UIImagePickerController , Please if anyone can guide me how to fix this. func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo  Image Picker Controller for iOS written in Swift 3.2 & 4. - zhangao0086/DKImagePickerController

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.

imagePickerController(_:didFinishPickingMediaWithInfo , iOS 3.0+; Mac Catalyst 13.0+. Framework. UIKit optional func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info:  Looking for swift 4.2 compatibility as Carthage will not install framework as it was built with swift 4.1.2 Thanks

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
    ...
}

Picking images with UIImagePickerController in Swift 5, This article was inspired by my previous attempt to solve the image picking issue in a protocol oriented way, but that article is nowadays a little bit  jignesh-stratecore changed the title Twitter kit now work in swift - 4.2 , xcode 10 Twitter kit not work in swift - 4.2 , xcode 10 Mar 15, 2019 Copy link Quote reply CearsKhush commented Aug 16, 2019

Swift4.2

 //MARK:- ImagePicker Controller Delegate
 //MARK:-

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    dismiss(animated: true, completion: nil)
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    if let chosenImage = info[.originalImage] as? UIImage {
        yourimage.contentMode = .scaleAspectFill
        yourimage.image = chosenImage

    } else{
        print("Something went wrong")
    }
}

Choosing Images with UIImagePickerController in Swift, The UIImagePickerController is the easiest way to allow a user to select images on their device in order to load them into your Swift iOS app. Movie capture has a default duration limit of 10 minutes but can be adjusted using the video Maximum Duration property. When a user taps the Share button to send a movie to MMS, MobileMe, YouTube, or another destination, an appropriate duration limit and an appropriate video quality are enforced.

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

        if let pickedImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage {
            yourImage.image = pickedImage
        }else{
            print("Something went wrong!!")
        }
    }

How to Use UIImagePickerController for a Camera and Photo , This is a quick way as Swift has simplified much of the code for it. We'll be talking about some of the issues with camera on both iPad and  Swift version: 5.1 Paul Hudson @twostraws May 28th 2019 UIKit has a built-in view controller designed to let the user take photos, crop them as needed, them load them directly into your app.

Project 10, r/hackingwithswift: Following the [Swift coding projects on Project 10 - Problem with UIImageJPEGRepresentation, changed in 4.2? Instance method '​imagePickerController(_:didFinishPickingMediaWithInfo:)' nearly matches optional  SwiftyJSON is compatible with Swift 4 syntax and libraries, however because the project has "Swift 3.0" set in its build settings so you can't currently add it in as-is. I was able to include SwiftyJSON in my Swift 4 project by changing the build settings to use "Swift 4.0" and everything worked fine.

How to take a photo using the camera and UIImagePickerController , Elegant iOS form builder in Swift. Contribute to xmartlabs/Eureka development by creating an account on GitHub. Re: Issue MVisaQRParser with Swift 4.2 & above (XCode 10.2) I cannot provide the requested information as the IDE cannot compile to even run the app. I have no access to Mobile Push Payment Issuer SDK for QR parsing for iOS - Swift 5.0 as the last one I had links to was Mobile Push Payment Issuer SDK for QR parsing for iOS - Swift 4.0

Eureka/ImagePickerController.swift at master · xmartlabs/Eureka , #if swift(>=4.2). /// Presents the UIImagePickerController, resolving with the user action. public func promise(_ vc: UIImagePickerController, animate:  I just built my app against the latest pod with Xcode 10. After I did the Swift 4.2 migration on my project it compiled okay (although there are a lot of warnings about replacing “open let” with public).

Comments
  • and -> let image = info[.editedImage] as? UIImage
  • I would move self.profileImage.image = selectedImage! picker.dismiss(animated: true, completion: nil) outside of 'if/else' statement.
  • @Paragon yes you can "picker.dismiss(animated: true, completion: nil)" put this out of the condition. Thanks
  • Please edit the answer to use a plain text code block instead of an image of code.