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

I created the following code 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 to pass this dictionary in the above method as a parameter?

It should be noted that the method is in another class, and I call the method, creating its object as follows:

 let obj = Services() 

SignIn is defined in the Services.swift class so I'm trying to call it as

 obj.SignIn(objSignInDictionary) 

but getting the following error

 "String!" is not identical to "String" 

Where am I mistaken and how can I fix it. I got stuck here in a couple of days.

+6
source share
1 answer

If you click alt + click objSignInDictionary in Xcode, you will see that its value is specified as [String : String!] . You can fix this by explicitly setting the objSignInDictionary type:

 let objSignInDictionary:[String:String] = ["email":emailTextField.text, "password":passwordTextField.text] 
+12
source

Source: https://habr.com/ru/post/975991/


All Articles