This product is not supported for your selected Datadog site. ().
Metadata
ID:swift-code-style/guard-let-shorthand
Language: Unknown
Severity: Warning
Category: Code Style
Description
This rule identifies and flags redundant identifiers in optional binding within guard statements, such as guard let name = name else { ... }. In Swift, when the identifier on the left side of the binding is the same as the optional being unwrapped, you can omit the explicit assignment and write guard let name else { ... } instead. This simplification improves code readability by reducing unnecessary repetition.
To comply with this rule, simply omit the explicit assignment when unwrapping an optional with the same identifier, using guard let variable else { ... } rather than guard let variable = variable else { ... }. Always prefer this concise form unless you need to bind to a different variable name or perform type casting.