I knew that safely unwrapping is as follows
if let firstName = firstName
dictionary.setObject(firstName, forKey: "firstName")
dictionary.setObject("", forKey: "firstName")
I want to add firstname to dictionary even it is nil also. I will have 10-15 var's in dictionary. I do not want to check for this condition 10-15 times for ear var. I am having more than 1000 optionals through out project.
So thought of writing writing a func will help me duplicate the code and reduce the number of lines. So implemented this func as below.
func checkNull(str:String) -> String
return str.characters.count > 0 ? "\(str)" : ""
but while calling the func,
let addressstr = self.checkNull(address?.firstName)
firstname is the var in address model here. The auto correction sugguests
let addressstr = self.checkNull((address?.firstName)!)
The above line causes the crash.
Please let me know how can I fix this.