Hi ,
I use this below code ...
userProfile.login_date = memberData?["login_date"] as! String
The problem is if there is no value (I mean memberData?["login_date"] is null ) , the app falls down with error.
So I want to do this like, if memberData?["login_date"] is null, just do not input a value,
if there is a value, just put a value.
I can use "if" statement, but it seems like there is other simple way in swift ..
Could someone tell me how to do that ?
Thanks
Some suggestions…
If login_date property of userProfile is a String and you do not want to change its value when no date string is retrieved from the Optional Dictionary memberData:
if let date = memberData?["login_date"] as? String {
userProfile.login_date = date
}
If login_date property of userProfile is a String and you want to set it to some default value when no date string is retrieved from the Optional Dictionary memberData:
userProfile.login_date = memberData?["login_date"] as? String ?? defaultValue
If login_date property of userProfile is an Optional String and you want to set it to nil when no date string can be retrieved from the Optional Dictionary memberData:
userProfile.login_date = memberData?["login_date"] as? String