Swift ternary expression | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Swift ternary expression

Iā€™m try to write a ternary expression for my code, but I keep getting an error: ā€œresult values in '? :' expression have mismatching types '()' and 'Int' c%2 == 0 ? d = 0: d = 1ā€ My code has the following: let c = 7 var d = 0 c%2 == 0 ? d = 0 : d = 1 It should just set d to 0 or 1 depending on whether c is even or odd. I donā€™t understand what is wrong from the error message.

19th Jul 2019, 6:40 PM
Benjamin
0 Resposta