I'm new to Swift and I've got a beginner question! First - my environment is High Sierra 10.13.6 and I'm using Xcode 9.4.1. With that out of the way, I've created a func in which this piece of code throws an error at me.
The error is : error message :Â "Incorrect argument label in call (have 'imageFile: success:', expected 'image: success') ViewController.swift
if I change "imageFile" to "image" I get another error message that complains about a UIImage. Ideas on how to solve this?
Thank you in advance!
// My code snippet
visualRecognition.classify(imageFile: fileURL, success: { (classifiedImages) in
let classes = classifiedImages.images.first!.classifiers.first!.classes
It's hard to say without knowing more about your code. Specifically, what is the type of visualRecognition? Is that a system type or one of your own? If it’s one of your own, what does the declaration of the classify(imageFile:success:) method look like.
Thank you for taking a look. I'm pasted the entire function below...hopefully you can help me find my error. Thanks in advance!
//MARK: - DIDFINISHPICKINGMEDIAWITHINFO
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
imageView.image = image
imagePicker.dismiss(animated: true, completion: nil)
let visualRecognition = VisualRecognition(apiKey: apiKey, version: version)
let imageData = UIImageJPEGRepresentation(image, 0.01)
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
//let fileURL = documentsURL?.appendingPathComponent("tempImage.jpg")
let fileURL = documentsURL.appendingPathComponent("tempImage.jpg")
try? imageData?.write(to: fileURL, options: [])
//ERROR IS HERE
visualRecognition.classify(image: fileURL, success: { (classifiedImages) in
let classes = classifiedImages.images.first!.classifiers.first!.classes
self.classificationResults =
for index in 0..<classes.count {
self.classificationResults.append(classes[index].classification)
}
print(classifiedImages)
})
else {
print("There was an error picking the image")
}
}
Thank you for your answer. I'm trying to use IBM's to use visual recognition
for my app. So I think one my Carthage frameworks may be corrupted, specifically "VisualRecognitionV3." The example I'm working from is using that exact code without an error with Swift 4. So weird! It's possible the example is old enough that it's basically broken with any updates applied to it.