I am new to swift, so if this is question sounds stupid, please forgive me. Below is the example of optional binding. How it works, I understood. But why it is needed, I am unable to understand.
var optionalName: String? = "John Appleseed"
var greeting = "Hello!"
if let name = optionalName {
greeting = "Hello, \(name)"
}
Instead of using the new construct of "If let" we can use the below code. What is the harm in it? why we are taking an extra temporary variable altogether? Thanks in advance.
var optionalName: String = "John Appleseed"
var greeting = "Hello!"
if optionalName != nil {
greeting = "Hello, \(optionalName)"
}