0

I'm trying to pass some parameters to my Parse Cloud Code function, and receive the following error message in Xcode. cannot convert value of type '[String : String?]' to type '[NSObject : AnyObject]' in coercion. It works fine until I reference the incomingUser.objectId. Here's the code I'm passing:

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

Thanks for any help you can provide.

Robert
  • 1,499
  • 2
  • 14
  • 22

1 Answers1

1

try use params as [NSObject: AnyObject?] instead.

Or if the API require [NSObject: AnyObject], you would have to unwrap the objectId first.

guard let objectId = self.incomingUser.objectId else { return }

And then do

let params = ["userType" : userType, "recipient" : objectId]

PFCloud.callFunctionInBackground("pushNotification", withParameters: params as [NSObject : AnyObject]) {
(res: AnyObject?, error: NSError?) -> Void in
    print(res)
    print(error)
}
J.Wang
  • 1,136
  • 6
  • 12
  • The guard statement worked for this. Would you mind explaining why the "unwrapping" is required? Thanks so much for the help! – Robert Mar 07 '16 at 01:29
  • I would recommend [this](http://stackoverflow.com/questions/24034483/what-is-an-unwrapped-value-in-swift) answer for reference. I'm not quite good at explaining things in English:P. But let me know if you have any other puzzle after reading the above answer. – J.Wang Mar 07 '16 at 01:34