Hello guys,
I have a simple question about return statements in swift.
In Kotlin, you can do something like this:
fun foo(argument: String): String {
return when (argument) {
"huhu!" -> "nice"
"hi" -> "..."
else -> ""
}
}
foo("hi") // will return "..."
/*
The kotlin "when" expression is similar to swift's switch,
notice the lifted-out return statement.
*/
For the same thing, in swift the way i knew is:
func foo(_ argument: String) -> String {
switch argument {
case "huhu!": return "nice"
case "hi": return "..."
default: return ""
}
}
foo("hi") // will return "..."
So my question is, is there a way to also do the return-lift-out in swift?
Thank you for your answers!
~ Finder