J.M J.M - 1 month ago 5
Swift Question

How to pass two parameters in Swift

I am trying to pass in two parameters in the line

PFCloud...
. The code works when I just implement
"token":myVal
for the
withParameters
parameter, but doesn't work when I try to add
useremail
as well. I would like to know how I can do so.

var useremail = PFUser.currentUser()?.objectForKey("username") as! String
PFCloud.callFunctionInBackground("customer", withParameters: ["token":myVal] && ["email":useremail], block: { (success: AnyObject?, error: NSError?) -> Void in

Answer

Parameters is of type Dictionary. To add an element to a Dictionary, you need to separate the key-value pairs with a comma.

So instead of:

["token":myVal] && ["email":useremail]

You want:

["token":myVal, "email":useremail]

Because:

["token":myVal] && ["email":useremail]

Will be an expression of type Bool and not of type Dictionary.

Comments