by spott · 11y ago · 0 comments
const int a = [=](){
//do stuff here that returns an int:
if (condition) { return foo(); } else { return bar(); }
}();
Does this idiom work in swift? let x: String = {
if 3 == 4 {
return "Hello"
} else {
return "Goodbye"
}
}()
Although in this case, I'd just use ternary. let x = (3 == 4) ? "Hello" : "Goodbye"