One thing that I don't see mentioned in any of the existing answers here is that when unwrapping a variable, you don't have to use let with if or guard even though if let and guard let are often presented as the way to unwrap. As always in Swift, using let is appropriate for immutable values, and var is appropriate for mutable values. So, given:
let x: String? = "foo"
You can unwrap using if let if you don't plan to change the value:
if let x {
print(x)
}
But you can also use if var if you'd like to modify the value:
if var x {
print(x) // prints "foo"
x = "bar"
print(x) // prints "bar"
}
Of course, x is a different variable inside the body of the if statement, one that shadows the original x, and any changes that you make apply only to the copy in that shadow variable — if we add a print(x) after the closing } above, Swift will warn about implicitly converting String? to Any, but it will still print Optional("foo") as the value, so the let in the original declaration isn't violated.
The same is true for guard -- you can use guard var in cases where you'd like to be able to change your copy of the value.
Let's stop thinking of if let and guard let as magic formulae for unwrapping variables and instead know that if and guard can be used to unwrap an optional by assigning it to a new variable in the conditional's test.