Put the switch in an anonymous closure, if you’ll only use that code in one place.
string1 = {
switch var1 {
case 1:
return "hello"
case 2:
return "there"
default:
return "hello"
}
}()
Put the switch in an anonymous closure, if you’ll only use that code in one place.
string1 = {
switch var1 {
case 1:
return "hello"
case 2:
return "there"
default:
return "hello"
}
}()