使用 Swift PFIdResultBlock 错误解析云 [英] Parse Cloud with Swift PFIdResultBlock Error

查看:18
本文介绍了使用 Swift PFIdResultBlock 错误解析云的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 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)
            }
        }

我收到错误:

无法将(AnyObject?, NSError?) -> Void"类型的值转换为预期的参数类型PFIdResultBlock?"(又名'可选<(可选,可选)-> ()>')

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

即使我将 添加为!PFIdResultBlock,错误不会消失.

Even if I add as! PFIdResultBlock, the error will not go away.

我该如何解决这个问题?

How can I go about fixing this?

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

I definitely appreciate your help on this one!!

推荐答案

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

There is no need to specify the variable types while implementing the closure (Block in Objective-C) unlike Objective-C. You just need to change your code to the following:

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

这篇关于使用 Swift PFIdResultBlock 错误解析云的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆