in kotlin you can do this
val height = if height > 3.0 {
return "giant"
} else {
return "regular"
}
that is setting the value of a variable or constant using an if statement
is it possible to do the same thing in swift?
let height = if height > 3.0 {
return "giant"
} else {
return "regular"
}
I tried this for swift but i get Expected initial value after '=' error
You can use ternary operator in Swift
return height > 3.0 ? "giant" : "regular"
Also in Kotlin you can do
return if(height > 3.0) "giant" else "regular"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With