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.
we can use a ternary operator for example, ternary conditional operator (
question ? answer1 : answer2 ).
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