• Skip to primary navigation
  • Skip to content
  • Skip to footer
  • Home
  • |
  • Blog
  • |
  • TIL
  • |
  • Projects

Swift 5.9 if/switch Expressions

With Swift 5.9 we can now use if and switch statements on the right-hand side of the = sign, like this:

1
let result = if <some-condition> { .. } else { .. }

More examples here:

  • https://www.hackingwithswift.com/articles/258/whats-new-in-swift-5-9
  • https://stackoverflow.com/questions/77753645/can-we-use-a-nested-else-if-statement-to-assign-a-variable-instead-of-nested-ter

Tags: swift

Updated: January 31, 2026

Previous Next
  • Feed
© 2026 Dheeraj Neelam. Powered by Jekyll & Minimal Mistakes.