Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass dictionary as a parameter in the method in Swift?

I have created following method in my code:

func SignIn(objDictionary:Dictionary<String,String>)
{
    //Body of method
}

I need to pass the following dictionary as a parameter in this method which is defined below:

let objSignInDictionary:Dictionary = ["email":emailTextField.text, "password":passwordTextField.text]

How can I pass this dictionary in the above method as a parameter?

This should be noted that method is in another class and I am calling the method by creating its object as follows:

let obj = Services()

SignIn is defined in Services.swift class so I am trying to call it like

obj.SignIn(objSignInDictionary) 

but getting following error

"String!" is not identical to "String"

Where I am wrong and how it can be fixed. I am stuck here since couple of days.

like image 599
Developer Avatar asked Sep 29 '14 09:09

Developer


1 Answers

If you alt+click objSignInDictionary in Xcode you will see its inferred as [String : String!]. You can fix this by explicitly setting objSignInDictionary type:

let objSignInDictionary:[String:String] = ["email":emailTextField.text, "password":passwordTextField.text]
like image 81
Kirsteins Avatar answered Sep 21 '22 04:09

Kirsteins