import Foundation
// Swift optionals let a variable hold either a value or nil, and you use unwrapping
// (if let, guard let, ??, or !) to safely access the underlying value.
// This unwraps only if the value exists.
// guard let — great for early exits inside functions
// guard let — great for early exits inside functions
func greet(_ input: String?) {
guard let name = input else {
print("Missing name")
return
}
print("Hello, \(name)")
}
// Example usage:
let userInput: String? = "Mr Sponge"
greet(userInput)
// Try with nil
let noName: String? = nil
greet(noName)
/*
run:
Hello, Mr Sponge
Missing name
*/