使用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)
}
}
我遇到了错误:
无法将类型'(AnyObject ?, NSError?)-> Void'的值转换为 预期的参数类型为"PFIdResultBlock?" (又名 'Optional<(可选,可选)->()>')
Cannot convert value of type '(AnyObject?, NSError?) -> Void' to expected argument type 'PFIdResultBlock?' (aka 'Optional<(Optional, Optional) -> ()>')
即使添加as! 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中的块)时,无需指定变量类型.您只需要将代码更改为以下内容即可:
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屋!