How To Use Swift’s Ternary Operator

Take advantage of syntactic sugar in Swift

Jeff Morhous
Level Up Coding
Published in
2 min readJan 17, 2021

--

A screenshot of a ternary operation in Swift

Ternary operators are beyond cool. They’re an easy way to do some if-else logic all on one line. Beyond that, they’re still easy to read and understand, so you don’t have to sacrifice readability for the ‘cool factor’ of using a language’s advanced features. In fact, it’s a great way to keep methods shorter and draw attention to…

--

--