The ternary operator in Swift

Federica Benacquista
2 min readMay 14, 2021

Do you remember those notes kids would pass around when we were in middle school asking “Do you like me”?

The ternary operator is the equivalent of them in code.

When you use the ternary operator you’re asking a question that can either be true or false. When it’s true, the code after the “?” gets executed and when it’s false, the code after the “:” gets executed.

--

--

Federica Benacquista

I’m a self taught iOS developer and soon to be entrepreneur. I like to explain tricky concepts as easily as possible and it’s exactly what I do here.