1

In C I can insert pairs of brackets to indicate a subscope.

int main() {
    int x = 5;
    {
        int y = 6;
        x += y; //Works
    }
    x = y+8; //Uh oh
}

In Swift, if I try something similar it will assume I'm trying to call the previous statement as a function, or errors for other reasons. How do I simply make a subscope in Swift, to deallocate variables earlier?

Sh_Khan
  • 93,445
  • 7
  • 57
  • 76

1 Answers1

1

You can try

do {   
     // insert sub scope code
}
Sh_Khan
  • 93,445
  • 7
  • 57
  • 76