Closed charlieMonroe closed 8 years ago
Good catch. I'm putting that into my to-do list for 2.0. (it's gonna be the biggest release so far. I hope the wait is worth it ;) )
Issue fixed as of the upcoming 2.0.
Example:
@implementation aClass
- (void)main {
switch (i) {
case 0: {
int o = i + 1;
// Etc.
break;
}
case 1:
NSLog(@"It's one");
break;
default:
NSLog(@"Another case...");
}
}
Output:
class aClass {
func main() {
switch i {
case 0:
var o: Int32 = i+1
// Etc.
break
case 1:
print("It's one")
break
default:
print("Another case...")
}
}
}
P.S. The only issue right now is with the formatting, which remains to be resolved in some later release...
This is valid in ObjC/C/C++:
Notice the
{
}
block after:
in the case - this forces the compiler to create new code block, in which it is valid to declare new variables. This is normally forbidden sinceswitch
in C-based languages is by default a single code block (which is why it is fallthrough by default) and can be chopped up usingbreak
.In Swift, this is completely legal even without the
{}
:iSwift currently converts this into a comment "Unimplemented".