Variables with a value check if nil Swift 5.1
If you don’t want to set a default value to your variable you will have to write your variable like this:
var myNilVariable: String?
// now you can test whether the variable has a value or not
if myNilVariable == nil
{
print("nothing there")
}
// though if you assign a string variable to this then you will not be able to check if it is nil
// unless you have the ? After the variables declaration String
var myNilVariable:String? = "Hi"
// now you can test whether the variable has a value or not
if myNilVariable == nil
{
print("nothing there")
}