
Swift by Sundell · 7 min readSwift & Apple platforms
The power and limitations of using Swift statements as expressions
Swift 5.9 lets if and switch act as expressions, enabling concise returns, assignments, and error throws. The guide shows practical patterns, explains current limits, and offers workarounds, helping developers write cleaner Swift code.
- Use if/switch as expressions for concise returns and assignments.
- Wrap switch in a closure to use as an argument expression.
- Add explicit type annotations to resolve inference issues with nil branches.