What is optional binding? Swift 5.1
This will check if there is a value and assign it to a value.
var str = "Hello, playground"
var bill:String?
if let str = bill
{
print("ok we have something -- \(str)")
}
else
{
print("nothing there bill is equal to \(bill ?? "nil")")
}
In this case bill is nil so I’m defining a default string to the value so the program doesn’t crash. Using ??
preformatted