if let safely unwraps an optional:
if let
let value: int? = 42 if let v = value { print("Value: {v}") // only runs if not nil } else { print("Was nil") }
Goal: Use if let to print the length of an optional name, or "Name not provided" if nil.
Run the code to see the output
9 results