Swift is strongly typed so you need to know the type you are returning. Since you’re calling explain from cloud code, you should know what it’s returning. Note that queries in ParseSwift are able to be explained as well:
The simple solution is to use AnyDecodable (like the playground example above), in the your particular case:
struct ExplainType: Decodable {
let result: AnyDecodable
}
struct Cloud: ParseCloud {
//: Return type of your Cloud Function
typealias ReturnType = ExplainType
//: These are required for Object
var functionJobName: String
}
This is replicating the AnyResultResponse type:
You can see all of the generic return types ParseSwift uses in the file above.
Once you have AnyDecodable , you can cast the value to what you expect. I don’t use mongo, so I don’t know the types its explain returns, but you can look at the results you posted. You can try below to get through the first layer:
findQuery.runFunction { result in
switch result {
case .success(let results):
print("Response from cloud function: \(results.result))")
//If you know the type, use that instead of Any. If Any doesn't work use AnyDecodable again
guard let explainDictionary = results.result.value as? [String: Any] else {
return
}
print("Casted explain: \(explainDictionary)"
case .failure(let error):
print("Error calling cloud function: \(error)")
}
}