Guys pleeeaaaase explain me what do a quetion mark and a colon mean in swift? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Guys pleeeaaaase explain me what do a quetion mark and a colon mean in swift?

15th Feb 2016, 11:07 AM
David Chekirov
David Chekirov - avatar
2 Antworten
+ 4
When you see an expression like this: {conditional statement} ? {one thing} : {second thing} it is the same as: if ({conditional statement}) {one thing} else {second thing} the question mark and colon is just a shorter way of writing the if...else statement.
18th Apr 2016, 3:46 PM
Aaron Rose
0
it's called a ternary if statement. it's a shorthand way of writing an if else statement. Instead of writing this: var y: Bool car x = true if (x == true) { y = true } else { y = false } you can write: y = (x ? true : false) You would use it when you need to set a variable to a or b, or return or print a or b
14th Aug 2016, 9:44 PM
Luke Watts
Luke Watts - avatar