我试图将一些参数传递给我的Parse Cloud Code函数,并在Xcode中收到以下错误消息。 cannot convert value of type '[String : String?]' to type '[NSObject : AnyObject]' in coercion
。它工作正常,直到我引用incomingUser.objectId
。这是我传递的代码:
let params = ["userType" : userType, "recipient" : self.incomingUser.objectId]
PFCloud.callFunctionInBackground("pushNotification", withParameters: params as [NSObject : AnyObject]) {
(res: AnyObject?, error: NSError?) -> Void in
print(res)
print(error)
}
感谢您提供的任何帮助。
答案 0 :(得分:1)
请尝试使用params as [NSObject: AnyObject?]
。
如果API需要[NSObject: AnyObject]
,则必须先打开objectId
。
guard let objectId = self.incomingUser.objectId else { return }
然后再做
let params = ["userType" : userType, "recipient" : objectId]
PFCloud.callFunctionInBackground("pushNotification", withParameters: params as [NSObject : AnyObject]) {
(res: AnyObject?, error: NSError?) -> Void in
print(res)
print(error)
}