jeudi 25 juillet 2019

What is difference between if..else and Nil-Coalescing Operator Swift 4

I just want to know what is the difference between if..else and Nil-Coalescing Operator and it's main use.

  • Syntax with Nil-Coalescing Operator.
lblGenres.textColor = genreSelected.contains(indexPath.row) ? colorWithHex(hex: COLORCODE.APP_THEME_COLOR) : colorWithHex(hex: COLORCODE.BLACK_COLOR)

  • if..else statement
if genreSelected.contains(indexPath.row)
{
  lblGenres.textColor = colorWithHex(hex: COLORCODE.APP_THEME_COLOR)
}
else
{
  lblGenres.textColor = colorWithHex(hex: COLORCODE.BLACK_COLOR)
}


Here i get both works properly but with the using of Nil-Coalescing Operator make syntax easy.

  • So i just want to know that, which condition or operator use is good and why?

Aucun commentaire:

Enregistrer un commentaire