I am currently converting my swift 2.3 code to swift 3 and I am getting the above error on the following line:
setSharedPassword(nil, account: account, completion: completion)
Would the appropriate solution be just to replace nil with ""? The error goes away when I do it. I am looking for an explanation. Please help.
If your setSharedPassword
func's first parameter is of type String
then you will not be able to set this as nil
because it is not optional. If you want to be able to set it as nil, then you could do something like this for your func:
func setSharedPassword(string: String?, account: ...)
The reason why "" works is because it is still a value for a String, just a value that has no characters.
Of course this answer is assuming this is your own func. If setSharedPassword
is not yours, then you either need to come up with a String that represents no password, or just supply "" as before.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With