Code refactor by using ternary operator instead of if..else..if statement in swift

Code duplication is a common issue which violates the DRY principle.

In order to solve the code duplication in case of a if..else..if statement where the else statement returns void.

if..else..if statement with else statement returning void

we can use a ternary operator for example, ternary conditional operator (question ? answer1 : answer2 ).

replacing if..else..if statement with ternary operator

we can solve the code duplication issue by using ternary conditional operator. Thus resolving the code duplication issue.

Software Engineer | M.Sc. Computer Science from Technische Universitaet Berlin

Software Engineer | M.Sc. Computer Science from Technische Universitaet Berlin