解析云时出现 Swift PFIdResultBlock 错误

Parse Cloud with Swift PFIdResultBlock Error

 PFCloud.callFunctionInBackground("hello", withParameters: ["test":"tester"]) {
            (response: AnyObject?, error: NSError?) -> Void in
            if error == nil {
                let responseString = response as? String
                print(responseString)
            } else {
                print(error!.description)
            }
        }

我收到错误:

Cannot convert value of type '(AnyObject?, NSError?) -> Void' to expected argument type 'PFIdResultBlock?' (aka 'Optional<(Optional, Optional) -> ()>')

即使我添加as! PFIdResultBlock,错误也不会消失。

我该如何解决这个问题?

非常感谢你在这方面的帮助!!

与Objective-C不同,在实现闭包(Block in Objective-C)时不需要指定变量类型。您只需将代码更改为以下内容:

PFCloud.callFunction(inBackground: "",
                         withParameters: ["": ""]) { (response, error) in
                            if error == nil {
                                let responseString = response as? String
                                print(responseString)
                            } else {
                                print(error?.localizedDescription)
                            }
}