Reputation: 47
**hello everyone ... I am trying to make an app recognition, simply I have an image view, text view and button and code is below .. my first issue is that my imageview isnt changing after picking a picture! .. my second issue that it tells me that "Arguments label image1 do not match any available overloads " any help pls ?
import UIKit
import CoreImage
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate{
@IBOutlet var myimage: UIImageView!
@IBOutlet var info: UITextView!
@IBAction func Import(_ sender: Any) {
// create image picker
let imagepicker = UIImagePickerController()
imagepicker.delegate=self
imagepicker.sourceType=UIImagePickerControllerSourceType.photoLibrary
self.present(imagepicker ,animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let Image1 = info[UIImagePickerControllerOriginalImage] as? UIImage {
myimage.image = Image1
}
self.dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
self.dismiss(animated: true, completion: nil)
}
// detect function
func detect(){
let image2 = CIImage (Image1:myimage.image!)!
// issue is here it says
"Arguments label image1 do not match any available overloads "
}
}
Upvotes: 0
Views: 94
Reputation: 1180
First issue: Looks like your delegate method declaration doesn't match the one in the protocol, so it's treated as a separate method. Xcode even gives a warning:
Instance method 'imagePickerController(picker:didFinishPickingMediaWithInfo:)' nearly matches optional requirement 'imagePickerController(_:didFinishPickingMediaWithInfo:)' of protocol 'UIImagePickerControllerDelegate'
Try changing this line:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
to:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
UPD: please also read @dfd's comments below on how to avoid this (quite a common) type of confusion.
Second issue: as already mentioned by others, you should pass the parameter as the initialiser properly. With minimum changes to your code it will be:
let image2 = CIImage (image: myimage.image!)!
However, the less exclamation marks (i.e. force unwrapping) the better; for more info on that, check Optional Chaining as an Alternative to Forced Unwrapping.
Upvotes: 1
Reputation: 4848
Your first problem is that you are missing the _
in your delegate call, just before picker:
and you need to write Any
instead of AnyObject
. It should be:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { //... }
Second problem, your function needs to be written like this:
let image2 = CIImage(image: myimage.image!)
Upvotes: 0
Reputation: 6067
This error because you have write error label
CIImage.init(image: <#T##UIImage#>)
you can do it like this
guard let image = myimage.image else {
return
}
let image2 = CIImage.init(image: image)
Upvotes: 0