ios killers
ios killers

Reputation: 109

Cannot convert value of type '[String : String?]' to expected argument type '[NSObject : AnyObject]?'

When I use Parse 1.8.5 to upload data to Parse, this cloud code has compile error in "params" that I cannot debug it.

       let params = ["phoneNumber" : userPhoneNumber, 
                    "username": username,
                    "password": userPassword,
                    "Email": userEmail
                     ]  

        PFCloud.callFunctionInBackground("sendCode", withParameters: params, block: 
              { (response: AnyObject?, error: NSError?) -> Void in
            if response?.localizedDescription != nil {
                print(error)
                var alert = UIAlertView(title: "Failure", message: "SignUp Error", delegate: self, cancelButtonTitle: "OK")
                alert.show()
            } else {
                self.activityIndicator.stopAnimating()
            }
        })

Upvotes: 10

Views: 14703

Answers (4)

Muhammad Hijazi
Muhammad Hijazi

Reputation: 23

Try this on to cast each element to AnyObject

    let params = ["phoneNumber" : userPhoneNumber as! AnyObject, 
                "username": username as! AnyObject,
                "password": userPassword as! AnyObject,
                "Email": userEmail as! AnyObject
                 ] 

Upvotes: 0

Joker
Joker

Reputation: 830

I had the Same Problem in my project. i just changed my code from let parameters = ["email": mail,"password":passCode ] to let parameters = ["email": mail as! AnyObject,"password":passCode as! AnyObject] . Not sure if it affects anything else.

Upvotes: 1

AAA
AAA

Reputation: 1977

It works for me.Try this:

let parameters = ["number": number, 
                  "username": username,
                  "password": userPassword,
                  "Email": userEmail]
PFCloud.callFunctionInBackground("sendCode", withParameters: parameters) { results, error in
            if error != nil {  
                 print(error)   
            } else {
                self.activityIndicator.stopAnimating() 
            }
}

Make sure number, username, userPassword, userEmail, sendCode are in the exact syntax in Parse Cloud

Upvotes: 0

vadian
vadian

Reputation: 285069

The error message says that there are optional types in the values of params.
Make sure that all values are unwrapped.

Upvotes: 16

Related Questions