Swift Ternary Operator

In this tutorial you will learn about the Swift Ternary Operator and its application with practical example.

Swift Ternary Operator

In swift, ternary (?:) operator is a shorthand method for if else statement, which allows to express if else statement in single line. It is also known as conditional operator.

Table Of Contents

Syntax:-

Here, condition is a Boolean expression that results in either True or False, if it results in True then result1 will be returned, if it results in False then result2 will be returned.

Example:-

Output:-

swift_ternary_operator

In this tutorial we have learn about the Swift Ternary Operator and its application with practical example. I hope you will like this tutorial.