好的,这是我的代码:
PFCloud.callFunctionInBackground("getRates", withParameters: ["test": "test"], block: {
(result: AnyObject!, error: NSError!) -> Void in
if ( error === nil) {
NSLog("Rates: \(result) ")
}
else if (error != nil) {
NSLog("error")
}
});
但是我得到一个错误:
Cannot invoke 'callFunctionInBackground' with an argument list of type
'(String, withParameters: [String : String], block: (AnyObject!, NSError!) -> Void)
有什么想法吗?
最佳答案
如果你为参数插入一个 NSMutableDictionary 实例而不是使用 Swift 字典字面量,错误就会消失。
尝试:
let params = NSMutableDictionary()
params.setObject( "test", forKey: "test" )
PFCloud.callFunctionInBackground("getRates", withParameters: params, block: {
(result: AnyObject!, error: NSError!) -> Void in
if ( error === nil) {
NSLog("Rates: \(result) ")
}
else if (error != nil) {
NSLog("error")
}
});
我想原因在于 NSDictionary 是一个 Cocoa 类,而 Dictionary 是一个原生的 Swift 结构。
关于ios - 在 Swift 中解析 PFCloud 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29312277/