0
votes

I'm having an issue/bug? where my https response returns JSON, as it should, but when i decode it, I'm suddenly told it is of type 'MLFeatureValue'?

Imported libraries:

  • Foundation
  • AVKit
  • UIKit
  • AVFoundation
  • Vision

Using:

  • Swift 4
  • Xcode 9.2
  • Project is ejected from react-native '0.54.3'

error message

var request = URLRequest(url: URL(string: "https://vision.googleapis.com/v1/images:annotate?key=fancyApiKey;)")!)

request.httpBody = jsonData
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
let task = self.urlSession.dataTask(with: request as URLRequest) { requestData, requestResponse, error in

  let parsedResult = try! JSONSerialization.jsonObject(with: requestData!, options: .allowFragments) as AnyObject
  print("data", parsedResult)

  guard let data = parsedResult["responses"] as? [String : AnyObject] else { return }

From the 'guard let data' line I get an error: "Cast from 'MLFeatureValue?!' to unrelated type '[String : AnyObject] always fails."

I have no idea where the 'MLFeatureValue' comes from, since I have nothing regarding machine learning imported in the file or even the project.

Thanks.

1

1 Answers

0
votes

Well, you have imported Vision. Vision uses a few ML classes and models. Please check out Apple's documentation.
Still not sure how Xcode is doing this. A workaround can be that while parsing you can use Any in place of AnyObject, or you can be more specific about your data which is expected to come in response.