Swift: 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.

If you like my articles please follow me. You can also support me by https://www.buymeacoffee.com/akarshseggemu

--

--

Akarsh Seggemu, M.Sc.
Akarsh Seggemu, M.Sc.

Written by Akarsh Seggemu, M.Sc.

IT Team Lead | Post graduate Computer Science from TU Berlin | Telugu writings are found in this account https://medium.com/@akarshseggemu_telugu

No responses yet