Search code examples
iosiphoneswiftxcodeidentifier

Use of unresolved identifier 'requestIPViewController' , Ambiguous reference to member 'subscript'


enter image description here it shows me there are some problems on the code

So How Can I fix that?

self.presentViewController[requestIPViewController, animated:YES, completion:nil];

}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
    let image = info[UIImagePickerControllerOriginalImage] as UIImage

Solution

  • If it is in swift 2.3 then it should be like that

    self.presentViewController(imagePicker, animated: true, completion: nil)
    

    And you must type cast it like it

    let image = info[UIImagePickerControllerOriginalImage]
                as! UIImage
    

    And swift 3.0 it looks like that

    self.present(imagePicker, animated: true, completion: nil)
    

    And detegate method looks like that

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    
        let mediaType = info[UIImagePickerControllerMediaType] as! NSString
    
        self.dismiss(animated: true, completion: nil)
    
        if mediaType.isEqual(to: kUTTypeImage as String) {
            let image = info[UIImagePickerControllerOriginalImage]
                as! UIImage
        }
    }
    

    Hope it helps.